Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #1369

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Cleanup #1369

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ android {
}

lintOptions {
abortOnError true
absolutePaths false
explainIssues false
htmlReport false
xmlReport false
textReport true
lintConfig file("${rootProject.getRootDir()}/lint.xml")
textReport true
warningsAsErrors true
abortOnError true
explainIssues false
absolutePaths false
xmlReport false
}

compileOptions {
Expand All @@ -55,41 +55,39 @@ android {
}

ext {
supportVersion = '28.0.0'
okHttpVersion = '3.9.1'
daggerVersion = '1.2.5'
leakCanaryVersion = '1.5.4'
retrofitVersion = '2.3.0'
roomVersion = '1.0.0'
archVersion = '1.1.0'
roomVersion = '2.2.2'
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0',
'androidx.recyclerview:recyclerview:1.0.0',
'androidx.cardview:cardview:1.0.0',
'com.google.android.material:material:1.0.0',
'androidx.preference:preference:1.0.0',
'androidx.browser:browser:1.0.0',
implementation "androidx.appcompat:appcompat:1.0.0",
"androidx.browser:browser:1.0.0",
"androidx.cardview:cardview:1.0.0",
"androidx.lifecycle:lifecycle-common-java8:2.0.0",
"androidx.lifecycle:lifecycle-extensions:2.0.0",
"androidx.preference:preference:1.0.0",
"androidx.recyclerview:recyclerview:1.0.0",
"androidx.room:room-runtime:$roomVersion",
"com.google.android.material:material:1.0.0",
"com.squareup.dagger:dagger:$daggerVersion",
"com.squareup.retrofit2:retrofit:$retrofitVersion",
"com.squareup.retrofit2:converter-gson:$retrofitVersion",
"com.squareup.retrofit2:adapter-rxjava:$retrofitVersion",
"com.squareup.okhttp3:okhttp:$okHttpVersion",
"com.squareup.okhttp3:logging-interceptor:$okHttpVersion",
"com.squareup.okhttp3:okhttp:$okHttpVersion",
"com.squareup.retrofit2:adapter-rxjava:$retrofitVersion",
"com.squareup.retrofit2:converter-gson:$retrofitVersion",
"com.squareup.retrofit2:retrofit:$retrofitVersion",
"io.reactivex:rxandroid:1.2.1",
"io.reactivex:rxjava:1.1.7",
'androidx.room:room-runtime:2.0.0',
'androidx.lifecycle:lifecycle-extensions:2.0.0',
'androidx.lifecycle:lifecycle-common-java8:2.0.0',
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

debugImplementation "com.squareup.leakcanary:leakcanary-android${rootProject.hasProperty("leak") ? "" : "-no-op"}:$leakCanaryVersion"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
kapt 'androidx.room:room-compiler:2.0.0',
kapt "androidx.room:room-compiler:$roomVersion",
"com.squareup.dagger:dagger-compiler:$daggerVersion"
kaptTest 'androidx.room:room-compiler:2.0.0',
kaptTest "androidx.room:room-compiler:$roomVersion",
"com.squareup.dagger:dagger-compiler:$daggerVersion"
}

Expand Down
75 changes: 41 additions & 34 deletions app/src/main/java/io/github/hidroh/materialistic/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,53 @@
package io.github.hidroh.materialistic

import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import androidx.annotation.IdRes
import androidx.appcompat.app.ActionBar
import android.view.MenuItem
import androidx.core.content.pm.PackageInfoCompat

class AboutActivity : InjectableActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
setSupportActionBar(findViewById(R.id.toolbar))

supportActionBar!!.displayOptions = ActionBar.DISPLAY_SHOW_HOME or
ActionBar.DISPLAY_HOME_AS_UP or ActionBar.DISPLAY_SHOW_TITLE

var versionName = ""
var versionCode = 0
try {
versionName = packageManager.getPackageInfo(packageName, 0).versionName
versionCode = packageManager.getPackageInfo(packageName, 0).versionCode
} catch (e: PackageManager.NameNotFoundException) {
// do nothing
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
setSupportActionBar(findViewById(R.id.toolbar))

supportActionBar!!.displayOptions = ActionBar.DISPLAY_SHOW_HOME or
ActionBar.DISPLAY_HOME_AS_UP or ActionBar.DISPLAY_SHOW_TITLE

var versionName = ""
var versionCode = 0
try {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
versionName = packageInfo.versionName
versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode.toInt()
} else {
PackageInfoCompat.getLongVersionCode(packageInfo).toInt()
}
} catch (e: PackageManager.NameNotFoundException) {
// do nothing
}

setTextWithLinks(R.id.text_application_info, getString(R.string.application_info_text, versionName, versionCode))
setTextWithLinks(R.id.text_developer_info, getString(R.string.developer_info_text))
setTextWithLinks(R.id.text_libraries, getString(R.string.libraries_text))
setTextWithLinks(R.id.text_license, getString(R.string.license_text))
setTextWithLinks(R.id.text_3rd_party_licenses, getString(R.string.third_party_licenses_text))
setTextWithLinks(R.id.text_privacy_policy, getString(R.string.privacy_policy_text))
}

private fun setTextWithLinks(@IdRes textViewResId: Int, htmlText: String) {
AppUtils.setTextWithLinks(findViewById(textViewResId), AppUtils.fromHtml(htmlText))
}

setTextWithLinks(R.id.text_application_info, getString(R.string.application_info_text, versionName, versionCode))
setTextWithLinks(R.id.text_developer_info, getString(R.string.developer_info_text))
setTextWithLinks(R.id.text_libraries, getString(R.string.libraries_text))
setTextWithLinks(R.id.text_license, getString(R.string.license_text))
setTextWithLinks(R.id.text_3rd_party_licenses, getString(R.string.third_party_licenses_text))
setTextWithLinks(R.id.text_privacy_policy, getString(R.string.privacy_policy_text))
}

private fun setTextWithLinks(@IdRes textViewResId: Int, htmlText: String) {
AppUtils.setTextWithLinks(findViewById(textViewResId), AppUtils.fromHtml(htmlText))
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
}
return super.onOptionsItemSelected(item)
}
}
71 changes: 44 additions & 27 deletions app/src/main/java/io/github/hidroh/materialistic/AppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.AttrRes;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
Expand All @@ -71,6 +65,13 @@
import androidx.core.util.Pair;
import androidx.core.view.GravityCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.ArrayList;
import java.util.List;

import io.github.hidroh.materialistic.annotation.PublicApi;
import io.github.hidroh.materialistic.data.HackerNewsClient;
import io.github.hidroh.materialistic.data.Item;
Expand All @@ -94,8 +95,12 @@ public class AppUtils {
private static final String HOST_ITEM = "item";
private static final String HOST_USER = "user";

public static void openWebUrlExternal(Context context, @Nullable WebItem item,
String url, @Nullable CustomTabsSession session) {
public static void openWebUrlExternal(
Context context,
@Nullable WebItem item,
String url,
@Nullable CustomTabsSession session
) {
if (!hasConnection(context)) {
context.startActivity(new Intent(context, OfflineWebActivity.class)
.putExtra(OfflineWebActivity.EXTRA_URL, url));
Expand All @@ -110,24 +115,29 @@ public static void openWebUrlExternal(Context context, @Nullable WebItem item,
}
List<ResolveInfo> activities = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

ArrayList<Intent> intents = new ArrayList<>();

for (ResolveInfo info : activities) {
if (info.activityInfo.packageName.equalsIgnoreCase(context.getPackageName())) {
continue;
}
intents.add(createViewIntent(context, item, url, session)
.setPackage(info.activityInfo.packageName));
intents.add(
createViewIntent(context, item, url, session)
.setPackage(info.activityInfo.packageName)
);
}
if (intents.isEmpty()) {
return;
}
if (intents.size() == 1) {
final int size = intents.size();
if (size == 1) {
context.startActivity(intents.remove(0));
} else {
context.startActivity(Intent.createChooser(intents.remove(0),
context.getString(R.string.chooser_title))
.putExtra(Intent.EXTRA_INITIAL_INTENTS,
intents.toArray(new Parcelable[intents.size()])));
intents.toArray(new Parcelable[size])));
}
}

Expand Down Expand Up @@ -191,7 +201,6 @@ public static CharSequence fromHtml(String htmlText, boolean compact) {
spanned = Html.fromHtml(htmlText, compact ?
Html.FROM_HTML_MODE_COMPACT : Html.FROM_HTML_MODE_LEGACY);
} else {
//noinspection deprecation
spanned = Html.fromHtml(htmlText);
}
return trim(spanned);
Expand All @@ -202,16 +211,22 @@ public static Intent makeSendIntentChooser(Context context, Uri data) {
// share receivers that accept only EXTRA_TEXT but not EXTRA_STREAM
return Intent.createChooser(new Intent(Intent.ACTION_SEND_MULTIPLE)
.setType("text/plain")
.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
new ArrayList<Uri>(){{add(data);}}),
.putParcelableArrayListExtra(
Intent.EXTRA_STREAM,
new ArrayList<Uri>() {{
add(data);
}}
),
context.getString(R.string.share_file));
}

public static void openExternal(@NonNull final Context context,
@NonNull PopupMenu popupMenu,
@NonNull View anchor,
@NonNull final WebItem item,
final CustomTabsSession session) {
public static void openExternal(
@NonNull final Context context,
@NonNull PopupMenu popupMenu,
@NonNull View anchor,
@NonNull final WebItem item,
final CustomTabsSession session
) {
if (TextUtils.isEmpty(item.getUrl()) ||
item.getUrl().startsWith(HackerNewsClient.BASE_WEB_URL)) {
openWebUrlExternal(context,
Expand Down Expand Up @@ -273,7 +288,7 @@ public static boolean isHackerNewsUrl(WebItem item) {

public static int getDimensionInDp(Context context, @DimenRes int dimenResId) {
return (int) (context.getResources().getDimension(dimenResId) /
context.getResources().getDisplayMetrics().density);
context.getResources().getDisplayMetrics().density);
}

public static void restart(Activity activity, boolean transition) {
Expand Down Expand Up @@ -332,7 +347,8 @@ public static Pair<String, String> getCredentials(Context context) {
* If no accounts exist in user's device, regardless of login status, prompt to login again
* If 1 or more accounts in user's device, and already logged in, prompt to update password
* If 1 or more accounts in user's device, and logged out, show account chooser
* @param context activity context
*
* @param context activity context
* @param alertDialogBuilder dialog builder
*/
@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -363,7 +379,6 @@ public static void registerAccountsUpdatedListener(final Context context) {
}, null, true);
}

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void openPlayStore(Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PLAY_STORE_URL));
Expand All @@ -382,8 +397,11 @@ public static void openPlayStore(Context context) {
}

@SuppressLint("MissingPermission")
public static void showAccountChooser(final Context context, AlertDialogBuilder alertDialogBuilder,
Account[] accounts) {
public static void showAccountChooser(
final Context context,
AlertDialogBuilder alertDialogBuilder,
Account[] accounts
) {
String username = Preferences.getUsername(context);
final String[] items = new String[accounts.length];
int checked = -1;
Expand Down Expand Up @@ -422,7 +440,6 @@ public void onClick(DialogInterface dialog, int which) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
AccountManager.get(context).removeAccount(accounts[selection], null, null, null);
} else {
//noinspection deprecation
AccountManager.get(context).removeAccount(accounts[selection], null, null);
}
dialog.dismiss();
Expand Down Expand Up @@ -532,6 +549,7 @@ public static void share(Context context, String subject, String text) {
context.startActivity(intent);
}
}

public static Uri createItemUri(@NonNull String itemId) {
return new Uri.Builder()
.scheme(BuildConfig.APPLICATION_ID)
Expand Down Expand Up @@ -628,7 +646,6 @@ public static void setTextAppearance(TextView textView, @StyleRes int textAppear
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
textView.setTextAppearance(textAppearance);
} else {
//noinspection deprecation
textView.setTextAppearance(textView.getContext(), textAppearance);
}
}
Expand Down
Loading