From 1cfdaf41fa7d4ce4cf7065d13667bef32c27066a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 27 Mar 2020 18:08:58 +0800 Subject: Implemented share and import themes. Fixed some issues of custom theme. --- .../Activity/CustomThemeListingActivity.java | 153 +++++++++++++++++++-- .../Activity/CustomizeThemeActivity.java | 3 +- .../CustomThemeListingRecyclerViewAdapter.java | 3 +- .../AsyncTask/InsertCustomThemeAsyncTask.java | 19 ++- .../infinityforreddit/CustomTheme/CustomTheme.java | 9 ++ .../Fragment/CopyTextBottomSheetFragment.java | 2 +- .../Fragment/CreateThemeBottomSheetFragment.java | 90 ++++++++++++ .../CustomThemeOptionsBottomSheetFragment.java | 9 +- .../SelectBaseThemeBottomSheetFragment.java | 78 ----------- .../Fragment/ShareLinkBottomSheetFragment.java | 2 +- .../drawable-night/ic_import_day_night_24dp.xml | 9 ++ .../main/res/drawable/ic_import_day_night_24dp.xml | 9 ++ .../res/layout/activity_custom_theme_listing.xml | 1 + app/src/main/res/layout/activity_rules.xml | 3 +- app/src/main/res/layout/activity_search_result.xml | 19 ++- ...tivity_subscribed_subreddits_multiselection.xml | 3 +- .../layout/activity_subscribed_thing_listing.xml | 3 +- .../layout/fragment_create_theme_bottom_sheet.xml | 99 +++++++++++++ .../fragment_select_base_theme_bottom_sheet.xml | 81 ----------- app/src/main/res/layout/item_user_custom_theme.xml | 12 +- app/src/main/res/values/strings.xml | 16 ++- 21 files changed, 423 insertions(+), 200 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CreateThemeBottomSheetFragment.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SelectBaseThemeBottomSheetFragment.java create mode 100644 app/src/main/res/drawable-night/ic_import_day_night_24dp.xml create mode 100644 app/src/main/res/drawable/ic_import_day_night_24dp.xml create mode 100644 app/src/main/res/layout/fragment_create_theme_bottom_sheet.xml delete mode 100644 app/src/main/res/layout/fragment_select_base_theme_bottom_sheet.xml diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java index b8fb82a4..45902fd8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -10,6 +12,7 @@ import android.widget.EditText; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -17,6 +20,9 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -29,18 +35,27 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.CustomThemeListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.AsyncTask.ChangeThemeNameAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.DeleteThemeAsyncTask; +import ml.docilealligator.infinityforreddit.AsyncTask.GetCustomThemeAsyncTask; +import ml.docilealligator.infinityforreddit.AsyncTask.InsertCustomThemeAsyncTask; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; +import ml.docilealligator.infinityforreddit.Fragment.CreateThemeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.CustomThemeOptionsBottomSheetFragment; -import ml.docilealligator.infinityforreddit.Fragment.SelectBaseThemeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils; -public class CustomThemeListingActivity extends BaseActivity implements CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener { +import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN; +public class CustomThemeListingActivity extends BaseActivity implements + CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener, + CreateThemeBottomSheetFragment.SelectBaseThemeBottomSheetFragmentListener { + + @BindView(R.id.coordinator_layout_custom_theme_listing_activity) + CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_customize_theme_listing_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_customize_theme_listing_activity) @@ -94,8 +109,8 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh customThemeViewModel.getAllCustomThemes().observe(this, adapter::setUserThemes); fab.setOnClickListener(view -> { - SelectBaseThemeBottomSheetFragment selectBaseThemeBottomSheetFragment = new SelectBaseThemeBottomSheetFragment(); - selectBaseThemeBottomSheetFragment.show(getSupportFragmentManager(), selectBaseThemeBottomSheetFragment.getTag()); + CreateThemeBottomSheetFragment createThemeBottomSheetFragment = new CreateThemeBottomSheetFragment(); + createThemeBottomSheetFragment.show(getSupportFragmentManager(), createThemeBottomSheetFragment.getTag()); }); } @@ -124,10 +139,10 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh } @Override - public void changeName(String oldName) { + public void changeName(String oldThemeName) { View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_theme_name, null); EditText themeNameEditText = dialogView.findViewById(R.id.theme_name_edit_text_edit_theme_name_dialog); - themeNameEditText.setText(oldName); + themeNameEditText.setText(oldThemeName); themeNameEditText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { @@ -141,13 +156,9 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh if (imm != null) { imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); } - new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldName, themeNameEditText.getText().toString()).execute(); - }) - .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { - if (imm != null) { - imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); - } + new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldThemeName, themeNameEditText.getText().toString()).execute(); }) + .setNegativeButton(R.string.cancel, null) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); @@ -157,12 +168,31 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh } @Override - public void delete(String name) { + public void shareTheme(String themeName) { + new GetCustomThemeAsyncTask(redditDataRoomDatabase, themeName, customTheme -> { + if (customTheme != null) { + String jsonModel = customTheme.getJSONModel(); + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard != null) { + ClipData clip = ClipData.newPlainText("simple text", jsonModel); + clipboard.setPrimaryClip(clip); + Snackbar.make(coordinatorLayout, R.string.theme_copied, Snackbar.LENGTH_SHORT).show(); + } else { + Snackbar.make(coordinatorLayout, R.string.copy_theme_faied, Snackbar.LENGTH_SHORT).show(); + } + } else { + Snackbar.make(coordinatorLayout, R.string.cannot_find_theme, Snackbar.LENGTH_SHORT).show(); + } + }).execute(); + } + + @Override + public void delete(String themeName) { new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(R.string.delete_theme) - .setMessage(getString(R.string.delete_theme_dialog_message, name)) + .setMessage(getString(R.string.delete_theme_dialog_message, themeName)) .setPositiveButton(R.string.yes, (dialogInterface, i) - -> new DeleteThemeAsyncTask(redditDataRoomDatabase, name, (isLightTheme, isDarkTheme, isAmoledTheme) -> { + -> new DeleteThemeAsyncTask(redditDataRoomDatabase, themeName, (isLightTheme, isDarkTheme, isAmoledTheme) -> { if (isLightTheme) { CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences( CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), lightThemeSharedPreferences); @@ -187,8 +217,101 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh EventBus.getDefault().unregister(this); } + public void shareTheme(CustomTheme customTheme) { + if (customTheme != null) { + String jsonModel = customTheme.getJSONModel(); + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard != null) { + ClipData clip = ClipData.newPlainText("simple text", jsonModel); + clipboard.setPrimaryClip(clip); + Snackbar.make(coordinatorLayout, R.string.theme_copied, Snackbar.LENGTH_SHORT).show(); + } else { + Snackbar.make(coordinatorLayout, R.string.copy_theme_faied, Snackbar.LENGTH_SHORT).show(); + } + } else { + Snackbar.make(coordinatorLayout, R.string.cannot_find_theme, Snackbar.LENGTH_SHORT).show(); + } + } + @Subscribe public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { recreate(); } + + @Override + public void importTheme() { + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard != null) { + // If it does contain data, decide if you can handle the data. + if (!clipboard.hasPrimaryClip()) { + Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); + } else if (clipboard.getPrimaryClipDescription() != null && + !clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) { + // since the clipboard has data but it is not plain text + Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); + } else if (clipboard.getPrimaryClip() != null){ + ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); + String json = item.getText().toString(); + try { + CustomTheme customTheme = new Gson().fromJson(json, CustomTheme.class); + checkDuplicateAndImportTheme(customTheme, true); + } catch (JsonSyntaxException e) { + Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); + } + } + } + } + + private void checkDuplicateAndImportTheme(CustomTheme customTheme, boolean checkDuplicate) { + new InsertCustomThemeAsyncTask(redditDataRoomDatabase, lightThemeSharedPreferences, + darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, checkDuplicate, + new InsertCustomThemeAsyncTask.InsertCustomThemeAsyncTaskListener() { + @Override + public void success() { + Snackbar.make(coordinatorLayout, R.string.import_theme_success, Snackbar.LENGTH_SHORT).show(); + } + + @Override + public void duplicate() { + new MaterialAlertDialogBuilder(CustomThemeListingActivity.this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.duplicate_theme_name_dialog_title) + .setMessage(getString(R.string.duplicate_theme_name_dialog_message, customTheme.name)) + .setPositiveButton(R.string.rename, (dialogInterface, i) + -> { + View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_theme_name, null); + EditText themeNameEditText = dialogView.findViewById(R.id.theme_name_edit_text_edit_theme_name_dialog); + themeNameEditText.setText(customTheme.name); + themeNameEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(CustomThemeListingActivity.this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.edit_theme_name) + .setView(dialogView) + .setPositiveButton(R.string.ok, (editTextDialogInterface, i1) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); + } + if (!themeNameEditText.getText().toString().equals("")) { + customTheme.name = themeNameEditText.getText().toString(); + } + checkDuplicateAndImportTheme(customTheme, true); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(editTextDialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0); + } + }) + .show(); + }) + .setNegativeButton(R.string.override, (dialogInterface, i) -> { + checkDuplicateAndImportTheme(customTheme, false); + }) + .show(); + } + }).execute(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java index e4847ac4..07730b0c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java @@ -198,7 +198,8 @@ public class CustomizeThemeActivity extends BaseActivity { } CustomTheme customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, themeName); new InsertCustomThemeAsyncTask(redditDataRoomDatabase, lightThemeSharedPreferences, - darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, () -> { + darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, + false, () -> { Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new RecreateActivityEvent()); finish(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java index 525564b8..3addc094 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java @@ -18,6 +18,7 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.CustomThemeListingActivity; import ml.docilealligator.infinityforreddit.Activity.CustomizeThemeActivity; import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme; import ml.docilealligator.infinityforreddit.Fragment.CustomThemeOptionsBottomSheetFragment; @@ -90,7 +91,7 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< activity.startActivity(intent); }); ((UserCustomThemeViewHolder) holder).shareImageView.setOnClickListener(view -> { - + ((CustomThemeListingActivity) activity).shareTheme(customTheme); }); ((UserCustomThemeViewHolder) holder).itemView.setOnClickListener(view -> { CustomThemeOptionsBottomSheetFragment customThemeOptionsBottomSheetFragment = new CustomThemeOptionsBottomSheetFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java index 5477ecbe..0eba4b1d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java @@ -13,22 +13,27 @@ public class InsertCustomThemeAsyncTask extends AsyncTask { private SharedPreferences darkThemeSharedPreferences; private SharedPreferences amoledThemeSharedPreferences; private CustomTheme customTheme; + private boolean checkDuplicate; private InsertCustomThemeAsyncTaskListener insertCustomThemeAsyncTaskListener; + private boolean isDuplicate = false; public interface InsertCustomThemeAsyncTaskListener { void success(); + default void duplicate() {} } public InsertCustomThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, SharedPreferences lightThemeSharedPreferences, SharedPreferences darkThemeSharedPreferences, - SharedPreferences amoledThemeSharedPreferences, CustomTheme customTheme, + SharedPreferences amoledThemeSharedPreferences, + CustomTheme customTheme, boolean checkDuplicate, InsertCustomThemeAsyncTaskListener insertCustomThemeAsyncTaskListener) { this.redditDataRoomDatabase = redditDataRoomDatabase; this.lightThemeSharedPreferences = lightThemeSharedPreferences; this.darkThemeSharedPreferences = darkThemeSharedPreferences; this.amoledThemeSharedPreferences = amoledThemeSharedPreferences; this.customTheme = customTheme; + this.checkDuplicate = checkDuplicate; this.insertCustomThemeAsyncTaskListener = insertCustomThemeAsyncTaskListener; } @@ -46,6 +51,12 @@ public class InsertCustomThemeAsyncTask extends AsyncTask { redditDataRoomDatabase.customThemeDao().unsetAmoledTheme(); CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences); } + if (checkDuplicate) { + if (redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name) != null) { + isDuplicate = true; + return null; + } + } redditDataRoomDatabase.customThemeDao().insert(customTheme); return null; } @@ -53,6 +64,10 @@ public class InsertCustomThemeAsyncTask extends AsyncTask { @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - insertCustomThemeAsyncTaskListener.success(); + if (isDuplicate) { + insertCustomThemeAsyncTaskListener.duplicate(); + } else { + insertCustomThemeAsyncTaskListener.success(); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java index 65409086..c05e79e0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java @@ -5,6 +5,8 @@ import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.PrimaryKey; +import com.google.gson.Gson; + import java.util.ArrayList; @Entity(tableName = "custom_themes") @@ -150,10 +152,17 @@ public class CustomTheme { @ColumnInfo(name = "is_change_status_bar_icon_color_after_toolbar_collapsed_in_immersive_interface") public boolean isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface; + public CustomTheme() {} + public CustomTheme(@NonNull String name) { this.name = name; } + public String getJSONModel() { + Gson gson = new Gson(); + return gson.toJson(this); + } + public static CustomTheme convertSettingsItemsToCustomTheme(ArrayList customThemeSettingsItems, String themeName) { CustomTheme customTheme = new CustomTheme(themeName); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java index 96bb671d..f53f6c09 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java @@ -98,7 +98,7 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copy_success, Toast.LENGTH_SHORT).show(); } else { - Toast.makeText(activity, R.string.copy_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.copy_link_failed, Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CreateThemeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CreateThemeBottomSheetFragment.java new file mode 100644 index 00000000..d92286ae --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CreateThemeBottomSheetFragment.java @@ -0,0 +1,90 @@ +package ml.docilealligator.infinityforreddit.Fragment; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.CustomizeThemeActivity; +import ml.docilealligator.infinityforreddit.R; + +/** + * A simple {@link Fragment} subclass. + */ +public class CreateThemeBottomSheetFragment extends RoundedBottomSheetDialogFragment { + + @BindView(R.id.import_theme_text_view_create_theme_bottom_sheet_fragment) + TextView importTextView; + @BindView(R.id.light_theme_text_view_create_theme_bottom_sheet_fragment) + TextView lightThemeTextView; + @BindView(R.id.dark_theme_text_view_create_theme_bottom_sheet_fragment) + TextView darkThemeTextView; + @BindView(R.id.amoled_theme_text_view_create_theme_bottom_sheet_fragment) + TextView amoledThemeTextView; + private Activity activity; + + public interface SelectBaseThemeBottomSheetFragmentListener { + void importTheme(); + } + + public CreateThemeBottomSheetFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_create_theme_bottom_sheet, container, false); + ButterKnife.bind(this, rootView); + + importTextView.setOnClickListener(view -> { + ((SelectBaseThemeBottomSheetFragmentListener) activity).importTheme(); + dismiss(); + }); + + lightThemeTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, CustomizeThemeActivity.class); + intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); + intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); + intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, getString(R.string.theme_name_indigo)); + startActivity(intent); + dismiss(); + }); + + darkThemeTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, CustomizeThemeActivity.class); + intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); + intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); + intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, getString(R.string.theme_name_indigo_dark)); + startActivity(intent); + dismiss(); + }); + + amoledThemeTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, CustomizeThemeActivity.class); + intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); + intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); + intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, getString(R.string.theme_name_indigo_amoled)); + startActivity(intent); + dismiss(); + }); + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (Activity) context; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CustomThemeOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CustomThemeOptionsBottomSheetFragment.java index 7657bba9..5529a599 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CustomThemeOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CustomThemeOptionsBottomSheetFragment.java @@ -7,8 +7,6 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; import android.widget.TextView; import androidx.annotation.NonNull; @@ -16,7 +14,6 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; import butterknife.BindView; import butterknife.ButterKnife; @@ -47,8 +44,9 @@ public class CustomThemeOptionsBottomSheetFragment extends RoundedBottomSheetDia } public interface CustomThemeOptionsBottomSheetFragmentListener { - void changeName(String oldName); - void delete(String name); + void changeName(String oldThemeName); + void shareTheme(String themeName); + void delete(String themeName); } @Override @@ -68,6 +66,7 @@ public class CustomThemeOptionsBottomSheetFragment extends RoundedBottomSheetDia }); shareThemeTextView.setOnClickListener(view -> { + ((CustomThemeOptionsBottomSheetFragmentListener) activity).shareTheme(themeName); dismiss(); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SelectBaseThemeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SelectBaseThemeBottomSheetFragment.java deleted file mode 100644 index 81df06c5..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SelectBaseThemeBottomSheetFragment.java +++ /dev/null @@ -1,78 +0,0 @@ -package ml.docilealligator.infinityforreddit.Fragment; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; - -import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.Activity.CustomizeThemeActivity; -import ml.docilealligator.infinityforreddit.R; - -/** - * A simple {@link Fragment} subclass. - */ -public class SelectBaseThemeBottomSheetFragment extends RoundedBottomSheetDialogFragment { - - @BindView(R.id.light_theme_text_view_select_base_theme_bottom_sheet_fragment) - TextView lightThemeTextView; - @BindView(R.id.dark_theme_text_view_select_base_theme_bottom_sheet_fragment) - TextView darkThemeTextView; - @BindView(R.id.amoled_theme_text_view_select_base_theme_bottom_sheet_fragment) - TextView amoledThemeTextView; - private Activity activity; - public SelectBaseThemeBottomSheetFragment() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_select_base_theme_bottom_sheet, container, false); - ButterKnife.bind(this, rootView); - - lightThemeTextView.setOnClickListener(view -> { - Intent intent = new Intent(activity, CustomizeThemeActivity.class); - intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); - intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); - intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, getString(R.string.theme_name_indigo)); - startActivity(intent); - dismiss(); - }); - - darkThemeTextView.setOnClickListener(view -> { - Intent intent = new Intent(activity, CustomizeThemeActivity.class); - intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); - intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); - intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, getString(R.string.theme_name_indigo_dark)); - startActivity(intent); - dismiss(); - }); - - amoledThemeTextView.setOnClickListener(view -> { - Intent intent = new Intent(activity, CustomizeThemeActivity.class); - intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); - intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); - intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, getString(R.string.theme_name_indigo_amoled)); - startActivity(intent); - dismiss(); - }); - return rootView; - } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ShareLinkBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ShareLinkBottomSheetFragment.java index d3c54782..4a2ed929 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ShareLinkBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ShareLinkBottomSheetFragment.java @@ -130,7 +130,7 @@ public class ShareLinkBottomSheetFragment extends RoundedBottomSheetDialogFragme clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copy_success, Toast.LENGTH_SHORT).show(); } else { - Toast.makeText(activity, R.string.copy_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.copy_link_failed, Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/res/drawable-night/ic_import_day_night_24dp.xml b/app/src/main/res/drawable-night/ic_import_day_night_24dp.xml new file mode 100644 index 00000000..eb39e3f3 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_import_day_night_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_import_day_night_24dp.xml b/app/src/main/res/drawable/ic_import_day_night_24dp.xml new file mode 100644 index 00000000..ad852174 --- /dev/null +++ b/app/src/main/res/drawable/ic_import_day_night_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_custom_theme_listing.xml b/app/src/main/res/layout/activity_custom_theme_listing.xml index 37b8f878..5b35b48c 100644 --- a/app/src/main/res/layout/activity_custom_theme_listing.xml +++ b/app/src/main/res/layout/activity_custom_theme_listing.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:id="@+id/coordinator_layout_custom_theme_listing_activity" tools:context=".Activity.CustomThemeListingActivity"> + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> diff --git a/app/src/main/res/layout/activity_search_result.xml b/app/src/main/res/layout/activity_search_result.xml index c4b132c7..63c8212e 100644 --- a/app/src/main/res/layout/activity_search_result.xml +++ b/app/src/main/res/layout/activity_search_result.xml @@ -14,12 +14,21 @@ android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_search_result_activity"> + + + + + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> diff --git a/app/src/main/res/layout/activity_subscribed_thing_listing.xml b/app/src/main/res/layout/activity_subscribed_thing_listing.xml index 183a0b61..460b1ba6 100644 --- a/app/src/main/res/layout/activity_subscribed_thing_listing.xml +++ b/app/src/main/res/layout/activity_subscribed_thing_listing.xml @@ -28,7 +28,8 @@ android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:layout_scrollFlags="scroll|enterAlways" - app:popupTheme="@style/AppTheme.PopupOverlay" /> + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> diff --git a/app/src/main/res/layout/fragment_create_theme_bottom_sheet.xml b/app/src/main/res/layout/fragment_create_theme_bottom_sheet.xml new file mode 100644 index 00000000..c5ac6fda --- /dev/null +++ b/app/src/main/res/layout/fragment_create_theme_bottom_sheet.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_select_base_theme_bottom_sheet.xml b/app/src/main/res/layout/fragment_select_base_theme_bottom_sheet.xml deleted file mode 100644 index d0adbd83..00000000 --- a/app/src/main/res/layout/fragment_select_base_theme_bottom_sheet.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_user_custom_theme.xml b/app/src/main/res/layout/item_user_custom_theme.xml index 55891961..e8c4dc65 100644 --- a/app/src/main/res/layout/item_user_custom_theme.xml +++ b/app/src/main/res/layout/item_user_custom_theme.xml @@ -24,21 +24,21 @@ android:textColor="?attr/primaryTextColor" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 22b971ff..a28dfd34 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -431,7 +431,7 @@ Copy Link Copied - Cannot copy the link + Cannot copy the link Copy Copy All Copy Markdown @@ -620,6 +620,20 @@ Are you sure to delete %1$s? Share Theme Change Name + Copied! Paste and share it to other people. + Cannot copy the theme configuration + Cannot find this theme + Import Theme + Cannot find data in clipboard + Import theme successful + Parse Theme Failed + Share it to r/Infinity_For_Reddit? + The theme configuration is copied! + Do you want to share it to r/Infinity so that other people can use it? + Duplicate Theme Found + A theme in the database is also called %1$s. Do you want to change the name of this imported theme? + Rename + Override Color Picker Invalid Color -- cgit v1.2.3