QBQuran
Komponen untuk mengakses daftar mushaf dan menampilkan Al-Quran digital.
Inisiasi Presenter​
private MushafPresenter mushafPresenter = new MushafPresenter(this);
mushafPresenter.attachView(this);
getMushafList​
Mengambil daftar mushaf yang tersedia dari server atau cache lokal.
mushafPresenter.getMushafList(String applicationId, String apiKey, boolean forceRefresh)
Parameters​
| Name | Type | Description |
|---|---|---|
applicationId | String | ID aplikasi dari BuildConfig.APPLICATION_ID |
apiKey | String | Kunci API dari BuildConfig.API_KEY |
forceRefresh | boolean | false = cache lokal; true = ambil dari server |
Returns​
List mushaf berisi nama dan ID untuk membuka Quran View.
Example​
mushafPresenter.getMushafList(
BuildConfig.APPLICATION_ID,
BuildConfig.API_KEY,
false
);
Cache Lokal
Gunakan forceRefresh = false untuk performa yang lebih baik. Data mushaf jarang berubah sehingga cache sudah cukup untuk sebagian besar kasus.
Open Quran View​
Membuka tampilan Al-Quran sesuai mushaf yang dipilih menggunakan Android Intent.
QuranImagePreference.setQuran(Context context, String quran)
Intent intent = new Intent(context, QuranImageActivity.class);
intent.putExtra(Static.QURAN_LAST, quran);
startActivity(intent);
Parameters​
| Name | Type | Description |
|---|---|---|
context | Context | Context dari Activity saat ini |
quran | String | Kode mushaf yang dipilih dari getMushafList |
Example​
String selectedMushaf = item.getStatus().toUpperCase();
QuranImagePreference.setQuran(this, selectedMushaf);
Intent intent = new Intent(this, QuranImageActivity.class);
intent.putExtra(Static.QURAN_LAST, selectedMushaf);
startActivity(intent);
Implementasi MushafView​
Activity harus mengimplementasikan interface MushafView untuk menerima callback.
MainActivity.java
public class MainActivity extends AppCompatActivity implements MushafView {
private MushafPresenter mushafPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mushafPresenter = new MushafPresenter(this);
mushafPresenter.attachView(this);
mushafPresenter.getMushafList(
BuildConfig.APPLICATION_ID,
BuildConfig.API_KEY,
false
);
}
@Override
public void onMushafLoaded(List<MushafItem> items) {
// Tampilkan di RecyclerView atau Spinner
}
@Override
public void onError(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
private void openSelectedMushaf(MushafItem item) {
QuranImagePreference.setQuran(this, item.getStatus().toUpperCase());
Intent intent = new Intent(this, QuranImageActivity.class);
intent.putExtra(Static.QURAN_LAST, item.getStatus().toUpperCase());
startActivity(intent);
}
@Override
protected void onDestroy() {
super.onDestroy();
mushafPresenter.detachView();
}
}