Search in sources :

Example 1 with TranslationRowData

use of com.quran.labs.androidquran.dao.translation.TranslationRowData in project quran_android by quran.

the class TranslationManagerActivity method removeItem.

private void removeItem(final TranslationRowData translationRowData) {
    if (adapter == null) {
        return;
    }
    final TranslationItem selectedItem = (TranslationItem) translationRowData;
    String msg = String.format(getString(R.string.remove_dlg_msg), selectedItem.name());
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.remove_dlg_title).setMessage(msg).setPositiveButton(R.string.remove_button, (dialog, id) -> {
        quranFileUtils.removeTranslation(TranslationManagerActivity.this, selectedItem.translation.getFileName());
        TranslationItem updatedItem = selectedItem.withTranslationRemoved();
        updateTranslationItem(updatedItem);
        // remove from active translations
        QuranSettings settings = QuranSettings.getInstance(this);
        Set<String> activeTranslations = settings.getActiveTranslations();
        activeTranslations.remove(selectedItem.translation.getFileName());
        settings.setActiveTranslations(activeTranslations);
        generateListItems();
    }).setNegativeButton(R.string.cancel, (dialog, i) -> dialog.dismiss());
    builder.show();
}
Also used : TranslationItem(com.quran.labs.androidquran.dao.translation.TranslationItem) AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) TranslationRowData(com.quran.labs.androidquran.dao.translation.TranslationRowData) SparseIntArray(android.util.SparseIntArray) QuranDownloadService(com.quran.labs.androidquran.service.QuranDownloadService) ServiceIntentHelper(com.quran.labs.androidquran.service.util.ServiceIntentHelper) Intent(android.content.Intent) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) TranslationsAdapter(com.quran.labs.androidquran.ui.adapter.TranslationsAdapter) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TranslationHeader(com.quran.labs.androidquran.dao.translation.TranslationHeader) R(com.quran.labs.androidquran.R) QuranFileUtils(com.quran.labs.androidquran.util.QuranFileUtils) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) ActionBar(android.support.v7.app.ActionBar) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) IntentFilter(android.content.IntentFilter) QuranDownloadNotifier(com.quran.labs.androidquran.service.util.QuranDownloadNotifier) Set(java.util.Set) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TranslationManagerPresenter(com.quran.labs.androidquran.presenter.translation.TranslationManagerPresenter) QuranApplication(com.quran.labs.androidquran.QuranApplication) File(java.io.File) Timber(timber.log.Timber) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) AlertDialog(android.support.v7.app.AlertDialog) TranslationItem(com.quran.labs.androidquran.dao.translation.TranslationItem) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) Snackbar(android.support.design.widget.Snackbar) Set(java.util.Set) QuranSettings(com.quran.labs.androidquran.util.QuranSettings)

Example 2 with TranslationRowData

use of com.quran.labs.androidquran.dao.translation.TranslationRowData in project quran_android by quran.

the class TranslationsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(TranslationViewHolder holder, int position) {
    TranslationRowData rowItem = translations.get(position);
    switch(holder.getItemViewType()) {
        case R.layout.translation_row:
            TranslationItem item = (TranslationItem) rowItem;
            holder.getTranslationTitle().setText(item.name());
            if (TextUtils.isEmpty(item.translation.getTranslatorNameLocalized())) {
                holder.getTranslationInfo().setText(item.translation.getTranslator());
            } else {
                holder.getTranslationInfo().setText(item.translation.getTranslatorNameLocalized());
            }
            ImageView leftImage = holder.getLeftImage();
            ImageView rightImage = holder.getRightImage();
            if (item.exists()) {
                if (item.needsUpgrade()) {
                    leftImage.setImageResource(R.drawable.ic_download);
                    leftImage.setVisibility(View.VISIBLE);
                    holder.getTranslationInfo().setText(R.string.update_available);
                } else {
                    leftImage.setVisibility(View.GONE);
                }
                rightImage.setImageResource(R.drawable.ic_cancel);
                rightImage.setVisibility(View.VISIBLE);
                rightImage.setContentDescription(context.getString(R.string.remove_button));
            } else {
                leftImage.setVisibility(View.GONE);
                rightImage.setImageResource(R.drawable.ic_download);
                rightImage.setVisibility(View.VISIBLE);
                rightImage.setOnClickListener(null);
                rightImage.setClickable(false);
                rightImage.setContentDescription(null);
            }
            break;
        case R.layout.translation_sep:
            holder.getSeparatorText().setText(rowItem.name());
            break;
    }
}
Also used : TranslationItem(com.quran.labs.androidquran.dao.translation.TranslationItem) TranslationRowData(com.quran.labs.androidquran.dao.translation.TranslationRowData) ImageView(android.widget.ImageView)

Example 3 with TranslationRowData

use of com.quran.labs.androidquran.dao.translation.TranslationRowData in project quran_android by quran.

the class TranslationManagerActivity method generateListItems.

private void generateListItems() {
    if (allItems == null) {
        return;
    }
    List<TranslationItem> downloaded = new ArrayList<>();
    List<TranslationItem> notDownloaded = new ArrayList<>();
    for (int i = 0, mAllItemsSize = allItems.size(); i < mAllItemsSize; i++) {
        TranslationItem item = allItems.get(i);
        if (item.exists()) {
            downloaded.add(item);
        } else {
            notDownloaded.add(item);
        }
    }
    List<TranslationRowData> result = new ArrayList<>();
    if (downloaded.size() > 0) {
        TranslationHeader hdr = new TranslationHeader(getString(R.string.downloaded_translations));
        result.add(hdr);
        boolean needsUpgrade = false;
        for (TranslationItem item : downloaded) {
            result.add(item);
            needsUpgrade = needsUpgrade || item.needsUpgrade();
        }
        if (!needsUpgrade) {
            quranSettings.setHaveUpdatedTranslations(false);
        }
    }
    result.add(new TranslationHeader(getString(R.string.available_translations)));
    result.addAll(notDownloaded);
    adapter.setTranslations(result);
    adapter.notifyDataSetChanged();
}
Also used : TranslationItem(com.quran.labs.androidquran.dao.translation.TranslationItem) TranslationHeader(com.quran.labs.androidquran.dao.translation.TranslationHeader) ArrayList(java.util.ArrayList) TranslationRowData(com.quran.labs.androidquran.dao.translation.TranslationRowData)

Aggregations

TranslationItem (com.quran.labs.androidquran.dao.translation.TranslationItem)3 TranslationRowData (com.quran.labs.androidquran.dao.translation.TranslationRowData)3 TranslationHeader (com.quran.labs.androidquran.dao.translation.TranslationHeader)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 Snackbar (android.support.design.widget.Snackbar)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SparseIntArray (android.util.SparseIntArray)1 MenuItem (android.view.MenuItem)1 ImageView (android.widget.ImageView)1 QuranApplication (com.quran.labs.androidquran.QuranApplication)1 R (com.quran.labs.androidquran.R)1 TranslationManagerPresenter (com.quran.labs.androidquran.presenter.translation.TranslationManagerPresenter)1