diff options
author | David-Development <david-dev@live.de> | 2021-08-22 12:40:29 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2021-08-22 12:40:29 +0300 |
commit | a10112fe3321fde384bff106fe20dfd1b0ba60fc (patch) | |
tree | d46e43b4e588bfcd14cc4f405671e964fddaff10 /News-Android-App/src/main/java | |
parent | 56d43b3b9ba4738d48cd2caadd42841478699c3a (diff) |
cleanup
Signed-off-by: David Luhmer <david-dev@live.de>
Diffstat (limited to 'News-Android-App/src/main/java')
3 files changed, 36 insertions, 109 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogActivity.java index 882e7f16..f4c9ace9 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogActivity.java @@ -21,6 +21,9 @@ package de.luhmer.owncloudnewsreader; +import static java.util.Objects.requireNonNull; +import static de.luhmer.owncloudnewsreader.Constants.MIN_NEXTCLOUD_FILES_APP_VERSION_CODE; + import android.annotation.SuppressLint; import android.app.Activity; import android.app.ProgressDialog; @@ -38,18 +41,11 @@ import android.text.util.Linkify; import android.util.Log; import android.util.Patterns; import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.RelativeLayout; import android.widget.TextView; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; -import com.google.android.material.textfield.TextInputLayout; import com.nextcloud.android.sso.AccountImporter; import com.nextcloud.android.sso.api.NextcloudAPI; import com.nextcloud.android.sso.exceptions.AccountImportCancelledException; @@ -63,7 +59,6 @@ import com.nextcloud.android.sso.ui.UiExceptionManager; import java.net.MalformedURLException; import java.net.URL; -import java.util.Objects; import javax.inject.Inject; @@ -79,9 +74,6 @@ import io.reactivex.annotations.NonNull; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import static de.luhmer.owncloudnewsreader.Constants.MIN_NEXTCLOUD_FILES_APP_VERSION_CODE; -import static java.util.Objects.requireNonNull; - /** * Activity which displays a login screen to the user, offering registration as * well. @@ -429,20 +421,19 @@ public class LoginDialogActivity extends AppCompatActivity { }); } - public static void ShowAlertDialog(String title, String text, Activity activity) - { - // Linkify the message - final SpannableString s = new SpannableString(text != null ? text : activity.getString(R.string.select_account_unknown_error_toast)); - Linkify.addLinks(s, Linkify.ALL); + public static void ShowAlertDialog(String title, String text, Activity activity) { + // Linkify the message + final SpannableString s = new SpannableString(text != null ? text : activity.getString(R.string.login_dialog_select_account_unknown_error_toast)); + Linkify.addLinks(s, Linkify.ALL); - AlertDialog aDialog = new AlertDialog.Builder(activity) - .setTitle(title) - .setMessage(s) - .setPositiveButton(activity.getString(android.R.string.ok) , null) - .create(); - aDialog.show(); + AlertDialog aDialog = new AlertDialog.Builder(activity) + .setTitle(title) + .setMessage(s) + .setPositiveButton(activity.getString(android.R.string.ok), null) + .create(); + aDialog.show(); - // Make the textview clickable. Must be called after show() + // Make the textview clickable. Must be called after show() ((TextView)aDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index dcd5f97e..606062f5 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -21,6 +21,11 @@ package de.luhmer.owncloudnewsreader; +import static androidx.annotation.VisibleForTesting.PROTECTED; +import static de.luhmer.owncloudnewsreader.LoginDialogActivity.RESULT_LOGIN; +import static de.luhmer.owncloudnewsreader.LoginDialogActivity.ShowAlertDialog; +import static de.luhmer.owncloudnewsreader.SettingsActivity.PREF_SERVER_SETTINGS; + import android.Manifest; import android.accounts.Account; import android.accounts.AccountManager; @@ -32,7 +37,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; -import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -101,7 +106,6 @@ import de.luhmer.owncloudnewsreader.databinding.ActivityNewsreaderBinding; import de.luhmer.owncloudnewsreader.events.podcast.FeedPanelSlideEvent; import de.luhmer.owncloudnewsreader.helper.DatabaseUtils; import de.luhmer.owncloudnewsreader.helper.ThemeChooser; -import de.luhmer.owncloudnewsreader.helper.ThemeUtils; import de.luhmer.owncloudnewsreader.model.OcsUser; import de.luhmer.owncloudnewsreader.reader.nextcloud.RssItemObservable; import de.luhmer.owncloudnewsreader.services.DownloadImagesService; @@ -118,11 +122,6 @@ import io.reactivex.functions.Action; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import static androidx.annotation.VisibleForTesting.PROTECTED; -import static de.luhmer.owncloudnewsreader.LoginDialogActivity.RESULT_LOGIN; -import static de.luhmer.owncloudnewsreader.LoginDialogActivity.ShowAlertDialog; -import static de.luhmer.owncloudnewsreader.SettingsActivity.PREF_SERVER_SETTINGS; - /** * An activity representing a list of NewsReader. This activity has different * presentations for handset and tablet-size devices. @@ -434,20 +433,19 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements } else if(exception instanceof TokenMismatchException) { Toast.makeText(NewsReaderListActivity.this, "Token out of sync. Please reauthenticate", Toast.LENGTH_LONG).show(); - try { - SingleAccountHelper.reauthenticateCurrentAccount(this); - } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException | NextcloudFilesAppNotSupportedException e) { - UiExceptionManager.showDialogForException(this, e); - } catch (NextcloudFilesAppAccountPermissionNotGrantedException e) { - // Unable to reauthenticate account just like that.. - startLoginActivity(); - } - //StartLoginFragment(this); - - } else { - UiExceptionManager.showDialogForException(this, (SSOException) exception); - //UiExceptionManager.showNotificationForException(this, (SSOException) exception); - } + try { + SingleAccountHelper.reauthenticateCurrentAccount(this); + } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException | NextcloudFilesAppNotSupportedException e) { + UiExceptionManager.showDialogForException(this, e); + } catch (NextcloudFilesAppAccountPermissionNotGrantedException e) { + // Unable to reauthenticate account just like that.. + startLoginActivity(); + } + //StartLoginFragment(this); + } else { + UiExceptionManager.showDialogForException(this, (SSOException) exception); + //UiExceptionManager.showNotificationForException(this, (SSOException) exception); + } } else { Toast.makeText(NewsReaderListActivity.this, exception.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } @@ -565,7 +563,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements @Override public void onUserInfoUpdated(OcsUser userInfo) { - final int placeHolder = R.drawable.ic_baseline_account_circle_24; + final Drawable placeHolder = getDrawable(R.drawable.ic_baseline_account_circle_24); DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder() .displayer(new CircleBitmapDisplayer()) .showImageOnLoading(placeHolder) @@ -575,7 +573,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements .cacheInMemory(true) .build(); - if(userInfo.getId() != null) { + if (userInfo.getId() != null) { String mOc_root_path = mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null); String avatarUrl = mOc_root_path + "/index.php/avatar/" + Uri.encode(userInfo.getId()) + "/64"; ImageLoader.getInstance().displayImage(avatarUrl, binding.toolbarLayout.avatar, displayImageOptions); @@ -731,8 +729,6 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements } }); - ThemeUtils.colorSearchViewCursorColor(mSearchView, Color.WHITE); - NewsReaderDetailFragment ndf = getNewsReaderDetailFragment(); if(ndf != null) { ndf.updateMenuItemsState(); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeUtils.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeUtils.java index 179c6728..3187b67d 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeUtils.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/ThemeUtils.java @@ -21,90 +21,30 @@ package de.luhmer.owncloudnewsreader.helper; -import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.os.Build; -import android.util.Log; import android.view.Menu; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ImageButton; -import android.widget.SearchView; -import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.RequiresApi; import androidx.appcompat.widget.ActionMenuView; import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; - -import java.lang.reflect.Field; - -import de.luhmer.owncloudnewsreader.R; public class ThemeUtils { - private static final String TAG = ThemeUtils.class.getCanonicalName(); + // private static final String TAG = ThemeUtils.class.getCanonicalName(); private ThemeUtils() {} /** - * Sets the color of the SearchView to {@code color} (cursor. - * @param searchView - */ - public static void colorSearchViewCursorColor(SearchView searchView, @ColorInt int color) { - try { - Field searchTextViewRef = SearchView.class.getDeclaredField("mSearchSrcTextView"); - searchTextViewRef.setAccessible(true); - Object searchAutoComplete = searchTextViewRef.get(searchView); - - // FIXME Reflective access to mTextSelectHandleRes will throw an exception when targeting API 30 and above - @SuppressLint("SoonBlockedPrivateApi") Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); - mCursorDrawableRes.setAccessible(true); - mCursorDrawableRes.set(searchAutoComplete, R.drawable.cursor); - - // Set color of handle - // https://stackoverflow.com/a/49555923 - - //get the pointer resource id - // FIXME Reflective access to mTextSelectHandleRes will throw an exception when targeting API 30 and above - @SuppressLint("SoonBlockedPrivateApi") Field textSelectHandleRef = TextView.class.getDeclaredField("mTextSelectHandleRes"); - textSelectHandleRef.setAccessible(true); - int drawableResId = textSelectHandleRef.getInt(searchAutoComplete); - - //get the editor - Field editorRef = TextView.class.getDeclaredField("mEditor"); - editorRef.setAccessible(true); - Object editor = editorRef.get(searchAutoComplete); - - //tint drawable - Drawable drawable = ContextCompat.getDrawable(searchView.getContext(), drawableResId); - drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); - - //set the drawable - Field mSelectHandleCenter = editor.getClass().getDeclaredField("mSelectHandleCenter"); - mSelectHandleCenter.setAccessible(true); - mSelectHandleCenter.set(editor, drawable); - - Field mSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft"); - mSelectHandleLeft.setAccessible(true); - mSelectHandleLeft.set(editor, drawable); - - Field mSelectHandleRight = editor.getClass().getDeclaredField("mSelectHandleRight"); - mSelectHandleRight.setAccessible(true); - mSelectHandleRight.set(editor, drawable); - } catch (Exception e) { - Log.w(TAG, "Couldn't apply color to search view cursor", e); - } - } - - - /** * Use this method to colorize the toolbar to the desired target color * @param toolbarView toolbar view being colored * @param toolbarBackgroundColor the target background color |