diff --git a/Alkitab/build.gradle b/Alkitab/build.gradle index 53906e32a..834d461e3 100644 --- a/Alkitab/build.gradle +++ b/Alkitab/build.gradle @@ -17,8 +17,8 @@ android { applicationId 'yuku.alkitab.debug' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 14000266 - versionName '4.4.0-beta6' + versionCode 14000267 + versionName '4.4.0-beta7' multiDexEnabled true // Keep this synced with build.gradle resConfigs! resConfigs 'af', 'bg', 'cs', 'da', 'de', 'es', 'fr', 'in', 'ja', 'lv', 'ms', 'nl', 'pl', 'pt', 'ro', 'ru', 'th', 'uk', 'zh-rCN', 'zh-rTW' @@ -93,6 +93,7 @@ dependencies { debugCompile "com.facebook.stetho:stetho-okhttp3:$stethoVersion" compile "com.android.support:support-v4:$supportLibVersion" compile "com.squareup.picasso:picasso:$picassoVersion" + compile "com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2" compile "com.squareup.okhttp3:okhttp:$okhttpVersion" compile "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion" compile 'net.sf.trove4j:trove4j:3.0.3' @@ -103,5 +104,5 @@ dependencies { compile 'com.android.support:multidex:1.0.1' compile "com.android.support:design:$supportLibVersion" compile "com.android.support:percent:$supportLibVersion" - compile "com.android.support:preference-v14:$supportLibVersion" + compile "com.takisoft.fix:preference-v7:$supportLibVersion.0" } diff --git a/Alkitab/src/main/AndroidManifest.xml b/Alkitab/src/main/AndroidManifest.xml index 2602cddc0..62ceadee1 100644 --- a/Alkitab/src/main/AndroidManifest.xml +++ b/Alkitab/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - @@ -72,21 +71,17 @@ + android:label="@string/pengaturan_alkitab" /> + android:configChanges="keyboardHidden|orientation|screenSize|locale|layoutDirection" /> + android:label="@string/activity_title_markers" /> + android:configChanges="keyboardHidden|orientation|screenSize|locale|layoutDirection"> @@ -281,12 +275,11 @@ + android:configChanges="keyboardHidden|orientation|screenSize|locale|layoutDirection" /> + android:label="@string/fm_activity_title" /> + android:label="Secret settings" /> + android:label="@string/sync_status_activity_title" /> + android:label="@string/sync_log_activity_title"/> + android:label="@string/sync_login_activity_title" /> + android:configChanges="keyboardHidden|orientation|screenSize|locale|layoutDirection" /> + android:label="@string/dv_activity_title"> @@ -496,8 +485,7 @@ + android:label="@string/dr_app_name" /> diff --git a/Alkitab/src/main/java/yuku/alkitab/base/App.java b/Alkitab/src/main/java/yuku/alkitab/base/App.java index 4b20e9443..d8ae30881 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/App.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/App.java @@ -2,7 +2,9 @@ import android.content.Context; import android.content.res.Configuration; +import android.graphics.Bitmap; import android.os.Build; +import android.support.annotation.NonNull; import android.support.multidex.MultiDex; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.preference.PreferenceManager; @@ -12,7 +14,10 @@ import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker; import com.google.gson.Gson; +import com.jakewharton.picasso.OkHttp3Downloader; import com.squareup.leakcanary.LeakCanary; +import com.squareup.picasso.Picasso; +import okhttp3.Cache; import okhttp3.Call; import okhttp3.Interceptor; import okhttp3.OkHttpClient; @@ -25,6 +30,7 @@ import yuku.alkitab.base.storage.Prefkey; import yuku.alkitab.base.sync.Gcm; import yuku.alkitab.base.sync.Sync; +import yuku.alkitab.debug.BuildConfig; import yuku.alkitab.debug.R; import yuku.alkitab.reminder.util.DevotionReminder; import yuku.alkitabfeedback.FeedbackSender; @@ -32,6 +38,7 @@ import yuku.kirimfidbek.CrashReporter; import yuku.stethoshim.StethoShim; +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.Locale; @@ -45,39 +52,29 @@ public class App extends yuku.afw.App { private static boolean initted = false; private static Tracker APP_TRACKER; + static final Interceptor userAgent = chain -> { + final Request originalRequest = chain.request(); + final Request requestWithUserAgent = originalRequest.newBuilder() + .removeHeader("User-Agent") + .addHeader("User-Agent", Version.userAgent() + " " + App.context.getPackageName() + "/" + App.getVersionName()) + .build(); + return chain.proceed(requestWithUserAgent); + }; + enum OkHttpClientWrapper { INSTANCE; - final OkHttpClient defaultClient; final OkHttpClient longTimeoutClient; { - final Interceptor userAgent = chain -> { - final Request originalRequest = chain.request(); - final Request requestWithUserAgent = originalRequest.newBuilder() - .removeHeader("User-Agent") - .addHeader("User-Agent", Version.userAgent() + " " + App.context.getPackageName() + "/" + App.getVersionName()) - .build(); - return chain.proceed(requestWithUserAgent); - }; - - { - final OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder.addNetworkInterceptor(userAgent); - StethoShim.addNetworkInterceptor(builder); - defaultClient = builder.build(); - } - - { - final OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder - .addNetworkInterceptor(userAgent) - .connectTimeout(300, TimeUnit.SECONDS) - .readTimeout(300, TimeUnit.SECONDS) - .writeTimeout(600, TimeUnit.SECONDS); - StethoShim.addNetworkInterceptor(builder); - longTimeoutClient = builder.build(); - } + final OkHttpClient.Builder builder = new OkHttpClient.Builder(); + builder + .addNetworkInterceptor(userAgent) + .connectTimeout(300, TimeUnit.SECONDS) + .readTimeout(300, TimeUnit.SECONDS) + .writeTimeout(600, TimeUnit.SECONDS); + StethoShim.addNetworkInterceptor(builder); + longTimeoutClient = builder.build(); } } @@ -88,19 +85,15 @@ enum GsonWrapper { } public static String downloadString(String url) throws IOException { - return OkHttpClientWrapper.INSTANCE.defaultClient.newCall(new Request.Builder().url(url).build()).execute().body().string(); + return downloadCall(url).execute().body().string(); } public static byte[] downloadBytes(String url) throws IOException { - return OkHttpClientWrapper.INSTANCE.defaultClient.newCall(new Request.Builder().url(url).build()).execute().body().bytes(); + return downloadCall(url).execute().body().bytes(); } public static Call downloadCall(String url) { - return OkHttpClientWrapper.INSTANCE.defaultClient.newCall(new Request.Builder().url(url).build()); - } - - public static OkHttpClient getOkHttpClient() { - return OkHttpClientWrapper.INSTANCE.defaultClient; + return okhttp().newCall(new Request.Builder().url(url).build()); } public static OkHttpClient getLongTimeoutOkHttpClient() { @@ -268,4 +261,49 @@ public static void trackEvent(final String category, final String action) { eventSubmitter.submit(() -> tracker.send(new HitBuilders.EventBuilder(category, action).build())); } } + + private static OkHttpClient okhttp; + + @NonNull + public static synchronized OkHttpClient okhttp() { + OkHttpClient res = okhttp; + if (res == null) { + final File cacheDir = new File(context.getCacheDir(), "okhttp-cache"); + if (!cacheDir.exists()) { + //noinspection ResultOfMethodCallIgnored + cacheDir.mkdirs(); + } + + final OkHttpClient.Builder builder = new OkHttpClient.Builder() + .cache(new Cache(cacheDir, 50 * 1024 * 1024)) + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .addNetworkInterceptor(userAgent); + + if (BuildConfig.DEBUG) { + builder.hostnameVerifier((hostname, session) -> true); + } + + StethoShim.addNetworkInterceptor(builder); + + okhttp = res = builder.build(); + } + return res; + } + + static Picasso picasso; + + @NonNull + public static synchronized Picasso picasso() { + Picasso res; + if (picasso == null) { + picasso = res = new Picasso.Builder(context) + .defaultBitmapConfig(Bitmap.Config.RGB_565) + .downloader(new OkHttp3Downloader(okhttp())) + .build(); + return res; + } + return picasso; + } } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.java index a06580c87..dbfb3d414 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.java @@ -94,6 +94,7 @@ import yuku.alkitab.base.widget.GotoButton; import yuku.alkitab.base.widget.LabeledSplitHandleButton; import yuku.alkitab.base.widget.LeftDrawer; +import yuku.alkitab.base.widget.MaterialDialogAdapterHelper; import yuku.alkitab.base.widget.ScrollbarSetter; import yuku.alkitab.base.widget.SingleViewVerseAdapter; import yuku.alkitab.base.widget.SplitHandleButton; @@ -425,12 +426,11 @@ public void onReceive(final Context context, final Intent intent) { toolbar = V.get(this, R.id.toolbar); setSupportActionBar(toolbar); - setTitle(""); - - final ActionBar actionBar = getSupportActionBar(); - assert actionBar != null; - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + ab.setDisplayShowTitleEnabled(false); + ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); bGoto = V.get(this, R.id.bGoto); bLeft = V.get(this, R.id.bLeft); @@ -1164,10 +1164,7 @@ void bGoto_click() { void bGoto_longClick() { App.trackEvent("nav_goto_button_long_click"); if (history.getSize() > 0) { - new MaterialDialog.Builder(this) - .adapter(historyAdapter, null) - .autoDismiss(true) - .show(); + MaterialDialogAdapterHelper.show(new MaterialDialog.Builder(this), new HistoryAdapter()); } else { Snackbar.make(root, R.string.recentverses_not_available, Snackbar.LENGTH_SHORT).show(); } @@ -1183,7 +1180,7 @@ public HistoryEntryHolder(final View itemView) { } } - private RecyclerView.Adapter historyAdapter = new RecyclerView.Adapter() { + class HistoryAdapter extends MaterialDialogAdapterHelper.Adapter { private final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(App.context); private final java.text.DateFormat mediumDateFormat = DateFormat.getMediumDateFormat(App.context); @@ -1222,6 +1219,8 @@ public void onBindViewHolder(final RecyclerView.ViewHolder _holder_, final int p } holder.itemView.setOnClickListener(v -> { + dismissDialog(); + final int which = holder.getAdapterPosition(); final int ari = history.getAri(which); @@ -1813,10 +1812,7 @@ public void onBookmarkAttributeClick(final Version version, final String version if (markers.size() == 1) { openBookmarkDialog(markers.get(0)._id); } else { - final MaterialDialog dialog = new MaterialDialog.Builder(IsiActivity.this) - .title(R.string.edit_bookmark) - .adapter(new MultipleMarkerSelectAdapter(version, versionId, markers, Marker.Kind.bookmark), null) - .show(); + MaterialDialogAdapterHelper.show(new MaterialDialog.Builder(IsiActivity.this).title(R.string.edit_bookmark), new MultipleMarkerSelectAdapter(version, versionId, markers, Marker.Kind.bookmark)); } } @@ -1830,10 +1826,7 @@ public void onNoteAttributeClick(final Version version, final String versionId, if (markers.size() == 1) { openNoteDialog(markers.get(0)._id); } else { - final MaterialDialog dialog = new MaterialDialog.Builder(IsiActivity.this) - .title(R.string.edit_note) - .adapter(new MultipleMarkerSelectAdapter(version, versionId, markers, Marker.Kind.note), null) - .show(); + MaterialDialogAdapterHelper.show(new MaterialDialog.Builder(IsiActivity.this).title(R.string.edit_note), new MultipleMarkerSelectAdapter(version, versionId, markers, Marker.Kind.note)); } } @@ -1853,7 +1846,7 @@ public MarkerHolder(final View itemView) { } } - class MultipleMarkerSelectAdapter extends RecyclerView.Adapter { + class MultipleMarkerSelectAdapter extends MaterialDialogAdapterHelper.Adapter { final Version version; final float textSizeMult; final List markers; @@ -1923,6 +1916,8 @@ public void onBindViewHolder(final RecyclerView.ViewHolder _holder_, final int p } holder.itemView.setOnClickListener(v -> { + dismissDialog(); + final int which = holder.getAdapterPosition(); final Marker marker = markers.get(which); if (kind == Marker.Kind.bookmark) { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/AboutActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/AboutActivity.java index 6ed4f9e68..5538c0aa8 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/AboutActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/AboutActivity.java @@ -9,6 +9,7 @@ import android.os.Bundle; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.widget.ContentLoadingProgressBar; +import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.text.method.LinkMovementMethod; import android.util.DisplayMetrics; @@ -23,11 +24,8 @@ import yuku.alkitab.base.util.Announce; import yuku.alkitab.debug.R; -import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; -import static com.afollestad.materialdialogs.MaterialDialog.Builder; -import static yuku.alkitab.base.util.Literals.Array; import static yuku.alkitab.base.util.Literals.List; public class AboutActivity extends BaseActivity { @@ -109,10 +107,10 @@ public void onLoaderReset(final Loader loader) { setContentView(R.layout.activity_about); final Toolbar toolbar = V.get(this, R.id.toolbar); - setSupportActionBar(toolbar); // must be done first before below lines - toolbar.setTitle(null); - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); - toolbar.setNavigationOnClickListener(v -> navigateUp()); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); root = V.get(this, R.id.root); tVersion = V.get(this, R.id.tVersion); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/ColorSettingsActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/ColorSettingsActivity.java index 42012400e..3be663869 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/ColorSettingsActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/ColorSettingsActivity.java @@ -2,8 +2,11 @@ import android.content.Intent; import android.os.Bundle; +import android.support.v7.app.ActionBar; import android.support.v7.preference.PreferenceFragmentCompat; +import android.support.v7.widget.Toolbar; import yuku.afw.App; +import yuku.afw.V; import yuku.alkitab.base.ac.base.BaseActivity; import yuku.alkitab.debug.R; @@ -19,10 +22,15 @@ public static Intent createIntent(final boolean nightMode) { } @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); super.onCreate(savedInstanceState); nightMode = getIntent().getBooleanExtra(EXTRA_nightMode, false); setContentView(R.layout.activity_color_settings); + + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); } public static class ColorSettingsFragment extends PreferenceFragmentCompat { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/DailyVerseAppWidgetConfigurationActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/DailyVerseAppWidgetConfigurationActivity.java index 8915b9a79..932651021 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/DailyVerseAppWidgetConfigurationActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/DailyVerseAppWidgetConfigurationActivity.java @@ -7,6 +7,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -52,10 +54,16 @@ public void onReceive(final Context context, final Intent intent) { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setResult(RESULT_CANCELED); setContentView(R.layout.activity_daily_verse_configuration); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + ab.setHomeAsUpIndicator(R.drawable.ic_action_remove); + final ListView lsVersionsAppWidget = V.get(this, R.id.lsVersionsAppWidget); final Button bOk = V.get(this, R.id.bOk); final Button bCancel = V.get(this, R.id.bCancel); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/FontManagerActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/FontManagerActivity.java index 58607039d..c30db787e 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/FontManagerActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/FontManagerActivity.java @@ -6,6 +6,8 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.IBinder; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -16,7 +18,6 @@ import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; import com.squareup.picasso.Callback; -import com.squareup.picasso.Picasso; import yuku.afw.V; import yuku.alkitab.base.App; import yuku.alkitab.base.ac.base.BaseActivity; @@ -38,7 +39,7 @@ public class FontManagerActivity extends BaseActivity implements DownloadService.DownloadListener { public static final String TAG = FontManagerActivity.class.getSimpleName(); - + private static final String URL_fontList = BuildConfig.SERVER_HOST + "addon/fonts/v1/list-v2.txt"; private static final String URL_fontData = BuildConfig.SERVER_HOST + "addon/fonts/v1/data/%s.zip"; private static final String URL_fontPreview = BuildConfig.SERVER_HOST + "addon/fonts/v1/preview/%s-384x84.png"; @@ -51,33 +52,39 @@ public static Intent createIntent() { FontAdapter adapter; TextView lEmptyError; DownloadService dls; - + private ServiceConnection serviceConnection = new ServiceConnection() { - @Override public void onServiceDisconnected(ComponentName name) { + @Override + public void onServiceDisconnected(ComponentName name) { dls = null; } - - @Override public void onServiceConnected(ComponentName name, IBinder service) { + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { dls = ((DownloadService.DownloadBinder) service).getService(); dls.setDownloadListener(FontManagerActivity.this); runOnUiThread(() -> loadFontList()); } }; - @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); + @Override + protected void onCreate(Bundle savedInstanceState) { super.willNeedStoragePermission(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_font_manager); - setTitle(R.string.fm_activity_title); + + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); lsFont = V.get(this, R.id.lsFont); lEmptyError = V.get(this, R.id.lEmptyError); - + lsFont.setAdapter(adapter = new FontAdapter()); lsFont.setEmptyView(lEmptyError); - + bindService(new Intent(App.context, DownloadService.class), serviceConnection, BIND_AUTO_CREATE); } @@ -90,9 +97,10 @@ protected void onNeededPermissionsGranted(final boolean immediatelyGranted) { } } - @Override protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); - + if (dls != null) { unbindService(serviceConnection); } @@ -101,8 +109,9 @@ protected void onNeededPermissionsGranted(final boolean immediatelyGranted) { void loadFontList() { new AsyncTask>() { String errorMsg; - - @Override protected List doInBackground(Void... params) { + + @Override + protected List doInBackground(Void... params) { try { final String listString = App.downloadString(URL_fontList); final List list = new ArrayList<>(); @@ -123,8 +132,9 @@ void loadFontList() { return null; } } - - @Override protected void onPostExecute(List result) { + + @Override + protected void onPostExecute(List result) { if (result != null) { lEmptyError.setText(null); adapter.setData(result); @@ -134,11 +144,11 @@ void loadFontList() { } }.execute(); } - + String getFontDownloadKey(String name) { return "FontManager/" + name; } - + private String getFontNameFromDownloadKey(String key) { if (!key.startsWith("FontManager/")) return null; return key.substring("FontManager/".length()); @@ -147,32 +157,36 @@ private String getFontNameFromDownloadKey(String key) { String getFontDownloadDestination(String name) { return new File(FontManager.getFontsPath(), "download-" + name + ".zip").getAbsolutePath(); } - + public static class FontItem { public String name; } - + public class FontAdapter extends BaseAdapter { List list; - + public void setData(List list) { this.list = list; notifyDataSetChanged(); } - @Override public int getCount() { - return list == null? 0: list.size(); + @Override + public int getCount() { + return list == null ? 0 : list.size(); } - @Override public FontItem getItem(int position) { + @Override + public FontItem getItem(int position) { return list.get(position); } - @Override public long getItemId(int position) { + @Override + public long getItemId(int position) { return position; } - @Override public View getView(int position, View convertView, ViewGroup parent) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { View res = convertView != null ? convertView : getLayoutInflater().inflate(R.layout.item_font_download, parent, false); final ImageView imgPreview = V.get(res, R.id.imgPreview); @@ -181,13 +195,13 @@ public void setData(List list) { final View bDelete = V.get(res, R.id.bDelete); final ProgressBar progressbar = V.get(res, R.id.progressbar); final TextView lErrorMsg = V.get(res, R.id.lErrorMsg); - + final FontItem item = getItem(position); final String dlkey = getFontDownloadKey(item.name); - + lFontName.setText(item.name); lFontName.setVisibility(View.VISIBLE); - Picasso.with(FontManagerActivity.this).load(String.format(URL_fontPreview, item.name)).into(imgPreview, new Callback.EmptyCallback() { + App.picasso().load(String.format(URL_fontPreview, item.name)).into(imgPreview, new Callback.EmptyCallback() { @Override public void onSuccess() { lFontName.setVisibility(View.GONE); @@ -199,7 +213,7 @@ public void onSuccess() { bDownload.setOnClickListener(bDownload_click); bDelete.setTag(R.id.TAG_fontItem, item); bDelete.setOnClickListener(bDelete_click); - + if (FontManager.isInstalled(item.name)) { progressbar.setIndeterminate(false); progressbar.setMax(100); @@ -255,10 +269,10 @@ public void onSuccess() { } } } - + return res; } - + private View.OnClickListener bDownload_click = v -> { FontItem item = (FontItem) v.getTag(R.id.TAG_fontItem); @@ -276,7 +290,7 @@ public void onSuccess() { notifyDataSetChanged(); }; - + private View.OnClickListener bDelete_click = v -> { final FontItem item = (FontItem) v.getTag(R.id.TAG_fontItem); @@ -302,22 +316,23 @@ public void onSuccess() { }; } - @Override public void onStateChanged(DownloadService.DownloadEntry entry, DownloadService.State originalState) { + @Override + public void onStateChanged(DownloadService.DownloadEntry entry, DownloadService.State originalState) { adapter.notifyDataSetChanged(); - + if (originalState == DownloadService.State.finished) { String fontName = getFontNameFromDownloadKey(entry.key); if (fontName == null) { // this download doesn't belong to font manager. return; } - + try { String downloadedZip = getFontDownloadDestination(fontName); File fontDir = FontManager.getFontDir(fontName); fontDir.mkdirs(); - + Log.d(TAG, "Going to unzip " + downloadedZip, new Throwable().fillInStackTrace()); - + ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(downloadedZip))); try { ZipEntry ze; @@ -339,7 +354,7 @@ public void onSuccess() { } finally { zis.close(); } - + new File(downloadedZip).delete(); } catch (Exception e) { new MaterialDialog.Builder(FontManagerActivity.this) @@ -350,7 +365,8 @@ public void onSuccess() { } } - @Override public void onProgress(DownloadService.DownloadEntry entry, DownloadService.State originalState) { + @Override + public void onProgress(DownloadService.DownloadEntry entry, DownloadService.State originalState) { adapter.notifyDataSetChanged(); } } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java index 4f0b56324..8b131d117 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java @@ -102,9 +102,7 @@ public void onPageSelected(int position) { tablayout = V.get(this, R.id.tablayout); tablayout.setTabMode(TabLayout.MODE_SCROLLABLE); - tablayout.setTabsFromPagerAdapter(pagerAdapter); - tablayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager)); - viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout)); + tablayout.setupWithViewPager(viewPager); if (savedInstanceState == null) { // get from preferences diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/HelpActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/HelpActivity.java index 2a6823bda..3e63d61a1 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/HelpActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/HelpActivity.java @@ -5,6 +5,8 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -64,10 +66,15 @@ public static Intent createViewAnnouncementIntent(final long[] announcementIds) @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_help); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + webview = V.get(this, R.id.webview); progress = V.get(this, R.id.progress); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkerListActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkerListActivity.java index c28b71355..80fda103f 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkerListActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkerListActivity.java @@ -7,6 +7,8 @@ import android.os.Bundle; import android.support.annotation.IdRes; import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.text.SpannableStringBuilder; import android.text.style.BackgroundColorSpan; import android.view.LayoutInflater; @@ -101,11 +103,15 @@ public static Intent createIntent(Context context, Marker.Kind filter_kind, long @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_marker_list); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + root = V.get(this, R.id.root); empty = V.get(this, android.R.id.empty); tEmpty = V.get(this, R.id.tEmpty); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkersActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkersActivity.java index 146ad5a53..9353aa57c 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkersActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/MarkersActivity.java @@ -7,6 +7,8 @@ import android.content.IntentFilter; import android.graphics.Point; import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -68,12 +70,15 @@ public static Intent createIntent() { } @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_markers); - setTitle(R.string.activity_title_markers); - + + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + adapter = new MarkerFilterAdapter(); adapter.reload(); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/NoteActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/NoteActivity.java index 55fccca12..1ee529374 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/NoteActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/NoteActivity.java @@ -3,6 +3,7 @@ import android.content.Intent; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; +import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.text.Layout; import android.text.SpannableStringBuilder; @@ -101,9 +102,10 @@ protected void onCreate(final Bundle savedInstanceState) { tCaption = V.get(this, R.id.tCaption); final Toolbar toolbar = V.get(this, R.id.toolbar); - setSupportActionBar(toolbar); // must be done first before below lines - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); - toolbar.setNavigationOnClickListener(v -> navigateUp()); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); if (marker != null) { tCaptionReadOnly.setText(marker.caption); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java index 8defb3572..a468c8e21 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/PatchTextActivity.java @@ -4,8 +4,10 @@ import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.util.TypedValue; -import android.view.View; +import android.view.Menu; +import android.view.MenuItem; import android.widget.EditText; import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; @@ -26,11 +28,10 @@ public class PatchTextActivity extends BaseActivity { public static final int REQCODE_send = 1; EditText tBody; - View bReference; - View bSend; CharSequence baseBody; String extraInfo; + String referenceUrl; public static Intent createIntent(final CharSequence baseBody, final String extraInfo, final String referenceUrl) { final Intent res = new Intent(App.context, PatchTextActivity.class); @@ -45,6 +46,13 @@ protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_patch_text); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + ab.setDisplayShowTitleEnabled(false); + tBody = V.get(this, R.id.tBody); tBody.setTextColor(S.applied.fontColor); tBody.setBackgroundColor(S.applied.backgroundColor); @@ -52,29 +60,11 @@ protected void onCreate(final Bundle savedInstanceState) { tBody.setTextSize(TypedValue.COMPLEX_UNIT_DIP, S.applied.fontSize2dp); tBody.setLineSpacing(0, S.applied.lineSpacingMult); - final ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setDisplayHomeAsUpEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setCustomView(R.layout.activity_patch_text_actionbar_custom); - - final View customView = actionBar.getCustomView(); - bReference = V.get(customView, R.id.bReference); - bSend = V.get(customView, R.id.bSend); - baseBody = getIntent().getCharSequenceExtra(EXTRA_baseBody); tBody.setText(baseBody, TextView.BufferType.EDITABLE); extraInfo = getIntent().getStringExtra(EXTRA_extraInfo); - final String referenceUrl = getIntent().getStringExtra(EXTRA_referenceUrl); - - if (referenceUrl != null) { - bReference.setOnClickListener(v -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(referenceUrl)))); - } else { - bReference.setVisibility(View.GONE); - } - - bSend.setOnClickListener(v -> bSend_click()); + referenceUrl = getIntent().getStringExtra(EXTRA_referenceUrl); new MaterialDialog.Builder(this) .content(R.string.patch_text_intro) @@ -82,7 +72,33 @@ protected void onCreate(final Bundle savedInstanceState) { .show(); } - void bSend_click() { + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + getMenuInflater().inflate(R.menu.activity_patch_text, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(final Menu menu) { + final MenuItem menuReference = menu.findItem(R.id.menuReference); + menuReference.setVisible(referenceUrl != null); + + return true; + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + if (item.getItemId() == R.id.menuReference) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(referenceUrl))); + return true; + } else if (item.getItemId() == R.id.menuSend) { + menuSend_click(); + } + + return super.onOptionsItemSelected(item); + } + + void menuSend_click() { final String baseText = baseBody.toString(); final String currentText = tBody.getText().toString(); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java index 214288224..24bb40db4 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/ReadingPlanActivity.java @@ -37,7 +37,9 @@ import yuku.alkitab.base.ac.base.BaseLeftDrawerActivity; import yuku.alkitab.base.model.ReadingPlan; import yuku.alkitab.base.storage.Prefkey; +import yuku.alkitab.base.util.Background; import yuku.alkitab.base.util.CurrentReading; +import yuku.alkitab.base.util.Foreground; import yuku.alkitab.base.util.ReadingPlanManager; import yuku.alkitab.base.util.Sqlitil; import yuku.alkitab.base.widget.LeftDrawer; @@ -406,7 +408,7 @@ private int calculateDaysDiff(Calendar startCalendar, Calendar endCalendar) { public boolean prepareDropDownNavigation() { if (downloadedReadingPlanInfos.size() == 0) { actionBar.setDisplayShowTitleEnabled(true); - actionBar.setTitle(R.string.rp_menuReadingPlan); + actionBar.setTitle(R.string.rp_activity_title); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); return true; } @@ -588,59 +590,42 @@ void downloadReadingPlanFromServer(final String name) { .dismissListener(dialog -> cancelled.set(true)) .show(); - new Thread() { - @Override - public void run() { - try { - download(); - } catch (Exception e) { - if (cancelled.get()) { - Log.e(TAG, "downloading reading plan data", e); + Background.run(() -> { + try { + final byte[] data = App.downloadBytes(BuildConfig.SERVER_HOST + "rp/get_rp?name=" + name); + if (cancelled.get()) return; + Foreground.run(() -> { + final long id = ReadingPlanManager.insertReadingPlanToDb(data, name); + + if (id == 0) { new MaterialDialog.Builder(ReadingPlanActivity.this) - .content(getString(R.string.rp_download_reading_plan_failed)) + .content(getString(R.string.rp_download_reading_plan_data_corrupted)) .positiveText(R.string.ok) .show(); + return; } - } finally { - pd.dismiss(); - } - } - - /** - * run on bg thread - */ - void download() throws Exception { - final byte[] bytes = App.downloadBytes(BuildConfig.SERVER_HOST + "rp/get_rp?name=" + name); - - if (cancelled.get()) return; - runOnUiThread(() -> onReadingPlanDownloadFinished(bytes)); - } - - /** - * run on ui thread - */ - void onReadingPlanDownloadFinished(final byte[] data) { - if (cancelled.get()) return; - final long id = ReadingPlanManager.insertReadingPlanToDb(data, name); - - if (id == 0) { - new MaterialDialog.Builder(ReadingPlanActivity.this) - .content(getString(R.string.rp_download_reading_plan_data_corrupted)) + Preferences.setLong(Prefkey.active_reading_plan_id, id); + loadReadingPlan(id); + loadReadingPlanProgress(); + loadDayNumber(); + prepareDropDownNavigation(); + prepareDisplay(); + supportInvalidateOptionsMenu(); + }); + } catch (Exception e) { + if (!cancelled.get()) { + Log.e(TAG, "downloading reading plan data", e); + Foreground.run(() -> new MaterialDialog.Builder(ReadingPlanActivity.this) + .content(getString(R.string.rp_download_reading_plan_failed)) .positiveText(R.string.ok) - .show(); - return; + .show() + ); } - - Preferences.setLong(Prefkey.active_reading_plan_id, id); - loadReadingPlan(id); - loadReadingPlanProgress(); - loadDayNumber(); - prepareDropDownNavigation(); - prepareDisplay(); - supportInvalidateOptionsMenu(); + } finally { + pd.dismiss(); } - }.start(); + }); } private float getActualPercentage() { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchActivity.java index 2ce723f17..88b3c7452 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchActivity.java @@ -12,6 +12,7 @@ import android.support.design.widget.Snackbar; import android.support.v4.graphics.ColorUtils; import android.support.v4.widget.CursorAdapter; +import android.support.v7.app.ActionBar; import android.support.v7.view.ActionMode; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; @@ -285,9 +286,10 @@ public static Intent createIntent(int openedBookId) { bEditFilter = V.get(this, R.id.bEditFilter); final Toolbar toolbar = V.get(this, R.id.toolbar); - setSupportActionBar(toolbar); // must be done first before below lines - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); - toolbar.setNavigationOnClickListener(v -> navigateUp()); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); bVersion = V.get(this, R.id.bVersion); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchBookFilterActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchBookFilterActivity.java index a2088115a..7b9d12ac4 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchBookFilterActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SearchBookFilterActivity.java @@ -5,8 +5,10 @@ import android.graphics.drawable.InsetDrawable; import android.os.Bundle; import android.os.Parcelable; +import android.support.v7.app.ActionBar; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; import android.util.SparseBooleanArray; import android.util.TypedValue; import android.view.Gravity; @@ -93,6 +95,12 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_book_filter); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + selectedBookIds = intArrayToSparseBooleanArray(getIntent().getIntArrayExtra(EXTRA_selectedBookIds)); final Parcelable[] booksParcelable = getIntent().getParcelableArrayExtra(EXTRA_books); final Book[] books = new Book[booksParcelable.length]; @@ -168,7 +176,7 @@ public VH onCreateViewHolder(final ViewGroup parent, final int viewType) { return new VH(getLayoutInflater().inflate(R.layout.search_book_filter_categories, parent, false), viewType); } else { final TextView res = new TextView(SearchBookFilterActivity.this); - res.setLayoutParams(new GridLayoutManager.LayoutParams(0 /* will be ignored */, getResources().getDimensionPixelSize(R.dimen.goto_grid_cell_height))); + res.setLayoutParams(new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.goto_grid_cell_height))); res.setGravity(Gravity.CENTER); res.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); return new VH(res, viewType); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSettingsActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSettingsActivity.java index 773a10858..5e76c7c91 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSettingsActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSettingsActivity.java @@ -2,11 +2,14 @@ import android.content.Intent; import android.os.Bundle; +import android.support.v7.app.ActionBar; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; +import android.support.v7.widget.Toolbar; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import gnu.trove.set.TLongSet; +import yuku.afw.V; import yuku.afw.storage.Preferences; import yuku.alkitab.base.App; import yuku.alkitab.base.S; @@ -97,9 +100,14 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_secret_settings); + + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); } public static Intent createIntent() { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSyncDebugActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSyncDebugActivity.java index ba64904d7..8999e908e 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSyncDebugActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SecretSyncDebugActivity.java @@ -33,6 +33,7 @@ import yuku.alkitab.base.sync.Sync_Mabel; import yuku.alkitab.base.sync.Sync_Pins; import yuku.alkitab.base.sync.Sync_Rp; +import yuku.alkitab.base.util.Background; import yuku.alkitab.base.util.Highlights; import yuku.alkitab.debug.BuildConfig; import yuku.alkitab.debug.R; @@ -442,7 +443,7 @@ public void onResponse(final Call call, final Response response) throws IOExcept .content("getting entities…") .show(); - new Thread(() -> { + Background.run(() -> { switch (syncSetName) { case SyncShadow.SYNC_SET_MABEL: entities.addAll(Sync_Mabel.getEntitiesFromCurrent()); @@ -480,6 +481,6 @@ public void onResponse(final Call call, final Response response) throws IOExcept .content("entities.size=" + entities.size() + " hash=" + String.format(Locale.US, "0x%08x", finalHashCode)) .positiveText("OK") .show()); - }).start(); + }); }; } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SettingsActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SettingsActivity.java index 35666d2d8..d5c4d19a3 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SettingsActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SettingsActivity.java @@ -6,12 +6,14 @@ import android.os.Handler; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBar; import android.support.v7.preference.CheckBoxPreference; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; @@ -65,10 +67,15 @@ private static Intent createSubIntent(Class @Override protected void onCreate(final Bundle savedInstanceState) { - super.enableNonToolbarUpButton(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + final String subClassName = getIntent().getStringExtra(EXTRA_subClassName); if (subClassName == null) { lsHeaders = V.get(this, R.id.lsHeaders); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/ShareActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/ShareActivity.java index 4dbc397d2..7d58e8c34 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/ShareActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/ShareActivity.java @@ -10,6 +10,8 @@ import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -58,10 +60,15 @@ public static Result obtainResult(Intent data) { } @Override protected void onCreate(Bundle savedInstanceState) { - enableNonToolbarUpButton(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_share); + final Toolbar toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); + String title = getIntent().getStringExtra(Intent.EXTRA_TITLE); setTitle(title); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SongListActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SongListActivity.java index cedd36f23..21c052b67 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SongListActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SongListActivity.java @@ -8,12 +8,12 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.CheckBox; @@ -127,18 +127,16 @@ public static Result obtainResult(Intent data) { } @Override protected void onCreate(Bundle savedInstanceState) { - supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_song_list); circular_progress = V.get(this, R.id.progress_circular); final Toolbar toolbar = V.get(this, R.id.toolbar); - setSupportActionBar(toolbar); // must be done first before below lines - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); - toolbar.setNavigationOnClickListener(v -> navigateUp()); - - setSupportProgressBarIndeterminate(true); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); searchView = V.get(this, R.id.searchView); lsSong = V.get(this, R.id.lsSong); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/SongViewActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/SongViewActivity.java index a290758ac..9b7ed14b8 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/SongViewActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/SongViewActivity.java @@ -28,7 +28,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.webkit.WebView; import android.webkit.WebViewClient; import com.afollestad.materialdialogs.MaterialDialog; @@ -42,7 +41,9 @@ import yuku.alkitab.base.storage.Prefkey; import yuku.alkitab.base.storage.SongDb; import yuku.alkitab.base.util.AlphanumComparator; +import yuku.alkitab.base.util.Background; import yuku.alkitab.base.util.FontManager; +import yuku.alkitab.base.util.Foreground; import yuku.alkitab.base.util.OsisBookNames; import yuku.alkitab.base.util.SongBookUtil; import yuku.alkitab.base.util.Sqlitil; @@ -165,7 +166,7 @@ static class MediaState { /** This method might be called from non-UI thread. Be careful when manipulating UI. */ @Override - public void setMediaState(final MediaPlayerController.ControllerState state) { + public void setMediaState(@NonNull final MediaPlayerController.ControllerState state) { if (state == MediaPlayerController.ControllerState.reset) { mediaState.enabled = false; mediaState.icon = R.drawable.ic_action_hollowplay; @@ -282,7 +283,7 @@ void playOrPause(final boolean playInLoop) { if (isMidiFile) { final Handler handler = new Handler(); - new Thread(() -> { + Background.run(() -> { try { setState(ControllerState.preparing); @@ -306,7 +307,7 @@ void playOrPause(final boolean playInLoop) { Log.e(TAG, "buffering to local cache", e); setState(ControllerState.error); } - }).start(); + }); } else { mediaPlayerPrepare(false, url, playInLoop); } @@ -399,7 +400,6 @@ public static Intent createIntent() { } @Override protected void onCreate(Bundle savedInstanceState) { - supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_song_view); @@ -407,8 +407,6 @@ public static Intent createIntent() { setCustomProgressBarIndeterminateVisible(false); - setTitle(R.string.sn_songs_activity_title); - drawerLayout = V.get(this, R.id.drawerLayout); leftDrawer = V.get(this, R.id.left_drawer); leftDrawer.configure(this, drawerLayout); @@ -421,7 +419,7 @@ public static Intent createIntent() { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); - drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { + drawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerOpened(final View drawerView) { drawer_opened(); @@ -532,7 +530,7 @@ void checkAudioExistance() { final String checkedBookName = currentBookName; final String checkedCode = currentSong.code; - new Thread(() -> { + Background.run(() -> { try { final String filename = getAudioFilename(checkedBookName, checkedCode); final String response = App.downloadString(BuildConfig.SERVER_HOST + "addon/audio/exists?filename=" + Uri.encode(filename)); @@ -559,7 +557,7 @@ void checkAudioExistance() { } catch (IOException e) { Log.e(TAG, "@@checkAudioExistance", e); } - }).start(); + }); } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -718,10 +716,10 @@ protected void deleteSongBook() { final String bookName = currentBookName; - new Thread(() -> { + Background.run(() -> { final int count = S.getSongDb().deleteSongBook(bookName); - runOnUiThread(() -> { + Foreground.run(() -> { pd.dismiss(); new MaterialDialog.Builder(this) @@ -730,7 +728,7 @@ protected void deleteSongBook() { .dismissListener(dialog -> displayAnySongOrFinish()) .show(); }); - }).start(); + }); } private StringBuilder convertSongToText(Song song) { diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java index b1c8fa49b..4267bd23c 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java @@ -23,6 +23,7 @@ import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.ActionBar; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.SpannableStringBuilder; @@ -118,9 +119,10 @@ protected void onCreate(Bundle savedInstanceState) { setTitle(R.string.kelola_versi); final Toolbar toolbar = V.get(this, R.id.toolbar); - setSupportActionBar(toolbar); // must be done first before below lines - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); - toolbar.setNavigationOnClickListener(v -> navigateUp()); + setSupportActionBar(toolbar); + final ActionBar ab = getSupportActionBar(); + assert ab != null; + ab.setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. @@ -132,9 +134,7 @@ protected void onCreate(Bundle savedInstanceState) { tablayout = V.get(this, R.id.tablayout); tablayout.setTabMode(TabLayout.MODE_SCROLLABLE); - tablayout.setTabsFromPagerAdapter(sectionsPagerAdapter); - tablayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager)); - viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout)); + tablayout.setupWithViewPager(viewPager); processIntent(getIntent(), "onCreate"); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseActivity.java index 93e3f7e89..060a13e3f 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/base/BaseActivity.java @@ -9,6 +9,7 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; +import android.support.annotation.CallSuper; import android.support.v4.app.ActivityCompat; import android.support.v4.app.NavUtils; import android.support.v4.app.TaskStackBuilder; @@ -37,7 +38,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Activity private static final int REQCODE_PERMISSION_storage = 1; private static final int REQCODE_permissionSettings = 9970; - private boolean enableNonToolbarUpButton; private boolean willNeedStoragePermission; private int lastKnownLocaleSerialNumber; @@ -82,13 +82,6 @@ protected void applyActionBarAndStatusBarColors() { } } - /** - * Call this from subclasses before super.onCreate() to enable up button. - */ - protected void enableNonToolbarUpButton() { - this.enableNonToolbarUpButton = true; - } - /** * Call this from subclasses before super.onCreate() to make * the activity ask for storage permission and do not proceed @@ -104,13 +97,6 @@ protected void onCreate(final Bundle savedInstanceState) { lastKnownLocaleSerialNumber = ChangeLanguageHelper.getLocaleSerialCounter(); - if (this.enableNonToolbarUpButton) { - final ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - } - if (willNeedStoragePermission) { askStoragePermission(); } @@ -213,8 +199,10 @@ protected void onActivityResult(final int requestCode, final int resultCode, fin super.onActivityResult(requestCode, resultCode, data); } - @Override public boolean onOptionsItemSelected(MenuItem item) { - if (enableNonToolbarUpButton && item.getItemId() == android.R.id.home) { + @CallSuper + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { navigateUp(); return true; } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/br/DailyVerseAppWidgetReceiver.java b/Alkitab/src/main/java/yuku/alkitab/base/br/DailyVerseAppWidgetReceiver.java index a9c371ee4..4b49435ec 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/br/DailyVerseAppWidgetReceiver.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/br/DailyVerseAppWidgetReceiver.java @@ -9,6 +9,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.graphics.Color; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -79,9 +80,11 @@ public static void buildUpdate(final Context context, final int appWidgetId, fin } if (savedState.darkText) { - rv.setTextColor(R.id.tReference, 0xff000000); + rv.setTextColor(R.id.tReference, Color.BLACK); rv.setImageViewResource(R.id.bPrev, R.drawable.ic_nav_left_dark); rv.setImageViewResource(R.id.bNext, R.drawable.ic_nav_right_dark); + } else { + rv.setTextColor(R.id.tReference, Color.WHITE); } rv.setFloat(R.id.tReference, "setTextSize", savedState.textSize); @@ -160,7 +163,7 @@ public void onReceive(final Context context, final Intent intent) { } final String appWidgetAction = bundle.getString("app_widget_action"); - if (appWidgetAction == null || !appWidgetAction.equals("update_widget")) { + if (!"update_widget".equals(appWidgetAction)) { return; } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java b/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java index d1808c3d5..0b07f2c56 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java @@ -16,7 +16,9 @@ import yuku.alkitab.base.model.MVersionDb; import yuku.alkitab.base.storage.YesReaderFactory; import yuku.alkitab.base.util.AddonManager; +import yuku.alkitab.base.util.Background; import yuku.alkitab.base.util.DownloadMapper; +import yuku.alkitab.base.util.Foreground; import yuku.alkitab.debug.R; import yuku.alkitab.io.BibleReader; import yuku.alkitab.io.OptionalGzipInputStream; @@ -31,10 +33,10 @@ public class VersionDownloadCompleteReceiver extends BroadcastReceiver { private static final String TAG = VersionDownloadCompleteReceiver.class.getSimpleName(); public VersionDownloadCompleteReceiver() { - } + } - @Override - public void onReceive(Context context, Intent intent) { + @Override + public void onReceive(Context context, Intent intent) { if (!DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) return; final long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); @@ -59,8 +61,8 @@ public void onReceive(Context context, Intent intent) { final String download_type = attrs.get("download_type"); - String preset_name = null; - int modifyTime = (int) (System.currentTimeMillis() / 1000L); + final String preset_name; + final int modifyTime; final String destPath; if ("preset".equals(download_type)) { @@ -87,81 +89,88 @@ public void onReceive(Context context, Intent intent) { final String filename_last_segment = attrs.get("filename_last_segment"); destPath = AddonManager.getVersionPath(filename_last_segment); + + preset_name = null; + modifyTime = (int) (System.currentTimeMillis() / 1000L); } else { Log.w(TAG, "unknown download_type for " + id + ": " + download_type); return; } - // transfer from dm to the actual file - final DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - - try { - final ParcelFileDescriptor pfd = dm.openDownloadedFile(id); - final FileInputStream fis = new FileInputStream(pfd.getFileDescriptor()); - final OptionalGzipInputStream ogis = new OptionalGzipInputStream(fis); - final AtomicFile af = new AtomicFile(new File(destPath)); - final FileOutputStream fos = af.startWrite(); - final byte[] buf = new byte[4096]; - while (true) { - final int read = ogis.read(buf); - if (read < 0) break; - fos.write(buf, 0, read); + // transfer from dm to the actual file in the background + Background.run(() -> { + final DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + + try { + final ParcelFileDescriptor pfd = dm.openDownloadedFile(id); + final FileInputStream fis = new FileInputStream(pfd.getFileDescriptor()); + final OptionalGzipInputStream ogis = new OptionalGzipInputStream(fis); + final AtomicFile af = new AtomicFile(new File(destPath)); + final FileOutputStream fos = af.startWrite(); + final byte[] buf = new byte[4096]; + while (true) { + final int read = ogis.read(buf); + if (read < 0) break; + fos.write(buf, 0, read); + } + af.finishWrite(fos); + pfd.close(); + } catch (IOException e) { + Log.e(TAG, "I/O error when saving downloaded version", e); + Foreground.run(() -> context.startActivity( + AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_saving_io_error)) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + )); + App.getLbm().sendBroadcast(new Intent(VersionsActivity.VersionListFragment.ACTION_RELOAD)); + return; + } finally { + DownloadMapper.instance.remove(id); } - af.finishWrite(fos); - pfd.close(); - } catch (IOException e) { - Log.e(TAG, "I/O error when saving downloaded version", e); - context.startActivity( - AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_saving_io_error)) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ); - App.getLbm().sendBroadcast(new Intent(VersionsActivity.VersionListFragment.ACTION_RELOAD)); - return; - } finally { - DownloadMapper.instance.remove(id); - } - final BibleReader reader = YesReaderFactory.createYesReader(destPath); - if (reader == null) { - new File(destPath).delete(); + final BibleReader reader = YesReaderFactory.createYesReader(destPath); + if (reader == null) { + new File(destPath).delete(); - context.startActivity( - AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_corrupted_file)) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ); - App.getLbm().sendBroadcast(new Intent(VersionsActivity.VersionListFragment.ACTION_RELOAD)); - return; - } + Foreground.run(() -> context.startActivity( + AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_corrupted_file)) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + )); + App.getLbm().sendBroadcast(new Intent(VersionsActivity.VersionListFragment.ACTION_RELOAD)); + return; + } - // success! + // success! - int maxOrdering = S.getDb().getVersionMaxOrdering(); - if (maxOrdering == 0) maxOrdering = MVersionDb.DEFAULT_ORDERING_START; + int maxOrdering = S.getDb().getVersionMaxOrdering(); + if (maxOrdering == 0) maxOrdering = MVersionDb.DEFAULT_ORDERING_START; - final MVersionDb mvDb = new MVersionDb(); - mvDb.locale = reader.getLocale(); - mvDb.shortName = reader.getShortName(); - mvDb.longName = reader.getLongName(); - mvDb.description = reader.getDescription(); - mvDb.filename = destPath; - if ("preset".equals(download_type)) { - mvDb.preset_name = preset_name; - } - mvDb.modifyTime = modifyTime; - mvDb.ordering = maxOrdering + 1; + final MVersionDb mvDb = new MVersionDb(); + mvDb.locale = reader.getLocale(); + mvDb.shortName = reader.getShortName(); + mvDb.longName = reader.getLongName(); + mvDb.description = reader.getDescription(); + mvDb.filename = destPath; + if ("preset".equals(download_type)) { + mvDb.preset_name = preset_name; + } + mvDb.modifyTime = modifyTime; + mvDb.ordering = maxOrdering + 1; - S.getDb().insertOrUpdateVersionWithActive(mvDb, true); - MVersionDb.clearVersionImplCache(); + S.getDb().insertOrUpdateVersionWithActive(mvDb, true); + MVersionDb.clearVersionImplCache(); - Toast.makeText(App.context, TextUtils.expandTemplate(context.getText(R.string.version_download_complete), mvDb.longName), Toast.LENGTH_LONG).show(); + Foreground.run(() -> { + Toast.makeText(App.context, TextUtils.expandTemplate(context.getText(R.string.version_download_complete), mvDb.longName), Toast.LENGTH_LONG).show(); - if ("ta".equals(mvDb.locale) || "te".equals(mvDb.locale) || "my".equals(mvDb.locale) || "el".equals(mvDb.locale)) { - context.startActivity( - AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_need_fonts)) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ); - } + if ("ta".equals(mvDb.locale) || "te".equals(mvDb.locale) || "my".equals(mvDb.locale) || "el".equals(mvDb.locale)) { + context.startActivity( + AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_need_fonts)) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + ); + } + }); - App.getLbm().sendBroadcast(new Intent(VersionsActivity.VersionListFragment.ACTION_RELOAD)); + App.getLbm().sendBroadcast(new Intent(VersionsActivity.VersionListFragment.ACTION_RELOAD)); + }); } } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/dialog/TypeBookmarkDialog.java b/Alkitab/src/main/java/yuku/alkitab/base/dialog/TypeBookmarkDialog.java index 1f683015b..dca13afd4 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/dialog/TypeBookmarkDialog.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/dialog/TypeBookmarkDialog.java @@ -15,6 +15,7 @@ import yuku.afw.V; import yuku.alkitab.base.S; import yuku.alkitab.base.U; +import yuku.alkitab.base.widget.MaterialDialogAdapterHelper; import yuku.alkitab.debug.R; import yuku.alkitab.model.Label; import yuku.alkitab.model.Marker; @@ -34,7 +35,6 @@ public interface Listener { final Context context; final Dialog dialog; FlowLayout panelLabels; - LabelAdapter adapter; EditText tCaption; Marker marker; @@ -81,16 +81,7 @@ private TypeBookmarkDialog(final Context context, final Marker marker, String re tCaption = V.get(dialogView, R.id.tCaption); final Button bAddLabel = V.get(dialogView, R.id.bAddLabel); - bAddLabel.setOnClickListener(v -> { - adapter = new LabelAdapter(); - - final MaterialDialog dialog = new MaterialDialog.Builder(context) - .title(R.string.add_label_title) - .adapter(adapter, null) - .build(); - - dialog.show(); - }); + bAddLabel.setOnClickListener(v -> MaterialDialogAdapterHelper.show(new MaterialDialog.Builder(context).title(R.string.add_label_title), new LabelAdapter())); if (marker != null) { labels = new TreeSet<>(); @@ -185,13 +176,13 @@ void setLabelsText() { int pos = 1; for (Label label: labels) { - panelLabels.addView(getLabelView(label), pos++); + panelLabels.addView(getLabelView(label, panelLabels), pos++); } } - private View getLabelView(Label label) { - TextView res = (TextView) LayoutInflater.from(context).inflate(R.layout.label_x, null); - res.setLayoutParams(panelLabels.generateDefaultLayoutParams()); + private View getLabelView(Label label, final ViewGroup parent) { + TextView res = (TextView) LayoutInflater.from(context).inflate(R.layout.label_x, parent, false); + res.setLayoutParams(this.panelLabels.generateDefaultLayoutParams()); res.setText(label.title); res.setTag(R.id.TAG_label, label); res.setOnClickListener(label_click); @@ -214,16 +205,12 @@ public LabelHolder(final View itemView) { } } - class LabelAdapter extends RecyclerView.Adapter { - private List