Skip to content

Commit

Permalink
Version 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHalvdansson committed Sep 23, 2023
1 parent d5a3d8a commit 259a36f
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 48 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.simon.harmonichackernews"
minSdkVersion 23
targetSdkVersion 34
versionCode 50
versionName "1.9.6"
versionCode 51
versionName "1.10"
compileSdk 34
buildToolsVersion = "34.0.0"

Expand Down
Binary file removed app/release/app-release.aab
Binary file not shown.
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 47,
"versionName": "1.9.3",
"versionCode": 51,
"versionName": "1.10",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void handleOnBackPressed() {
}
}
};
backPressedCallback.setEnabled(false);
toggleBackPressedCallback(false);
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), backPressedCallback);

swipeRefreshLayout.setOnRefreshListener(this::refreshComments);
Expand Down Expand Up @@ -393,6 +393,14 @@ public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowIn
}
}

private void toggleBackPressedCallback(boolean newStatus) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
backPressedCallback.setEnabled(newStatus);
} else {
backPressedCallback.setEnabled(true);
}
}

private void updateBottomSheetMargin(int navbarHeight) {
int standardMargin = Utils.pxFromDpInt(getResources(), Utils.isTablet(getResources()) ? 81 : 68);

Expand Down Expand Up @@ -572,9 +580,9 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@Override
public void onStateChanged(@NonNull View view, int newState) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
backPressedCallback.setEnabled(webView.canGoBack());
toggleBackPressedCallback(webView.canGoBack());
} else {
backPressedCallback.setEnabled(false);
toggleBackPressedCallback(false);
}
}

Expand Down Expand Up @@ -1406,7 +1414,7 @@ public void onPageFinished(WebView view, String url) {

if (BottomSheetBehavior.from(bottomSheet).getState() == BottomSheetBehavior.STATE_COLLAPSED) {
//if we are at the webview and we just loaded, recheck the canGoBack status
backPressedCallback.setEnabled(webView.canGoBack());
toggleBackPressedCallback(webView.canGoBack());
}
}

Expand Down Expand Up @@ -1497,14 +1505,14 @@ public long getSize() {
@JavascriptInterface
public void onLoad() {
if (mCallback != null) {
mHandler.post(() -> mCallback.onLoad());
mHandler.post(mCallback::onLoad);
}
}

@JavascriptInterface
public void onFailure() {
if (mCallback != null) {
mHandler.post(() -> mCallback.onFailure());
mHandler.post(mCallback::onFailure);
}
}

Expand All @@ -1519,7 +1527,7 @@ public void cleanUp() {
}

@Override
public void finalize() throws Throwable {
protected void finalize() throws Throwable {
try {
cleanUp();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private void updateFragmentLayout() {
private void showUpdateDialog() {
AlertDialog dialog = new MaterialAlertDialogBuilder(this)
.setTitle("Changelog")
.setMessage(Html.fromHtml("<b>Version 1.9.7:</b><br>" +
"- Added option to select start page (thanks Thomas Dalgetty)" +
.setMessage(Html.fromHtml("<b>Version 1.10:</b><br>" +
"- Added option to select start page (thanks Thomas Dalgetty)<br>" +
"- Comment scroll progress is now saved <br>" +
"- Posts can be marked as read/unread by long pressing and interacting with a small menu<br>" +
"- Added option to hide clicked posts<br>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ public boolean onPreferenceClick(Preference preference) {
if (getActivity() != null && getActivity() instanceof SettingsActivity) {
((SettingsActivity) getActivity()).backPressedCallback.setEnabled(true);
}
//TODO do we really need the above?

Snackbar snackbar = Snackbar.make(
requireView(),
Expand All @@ -295,18 +294,6 @@ public boolean onPreferenceClick(Preference preference) {
}
});

findPreference("pref_feedback").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "swesnowme@gmail.com" });
intent.putExtra(Intent.EXTRA_SUBJECT, "Harmonic for Hacker News feedback");
startActivity(Intent.createChooser(intent, "Send feedback"));
return false;
}
});

findPreference("pref_about").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public void onResume() {
adapter.notifyItemChanged(0);
attemptRefresh();
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -36,6 +43,9 @@

import java.util.Calendar;
import java.util.Date;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UserDialogFragment extends AppCompatDialogFragment {

Expand Down Expand Up @@ -75,15 +85,6 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Bundle bundle = getArguments();
final String userName = (bundle != null && !TextUtils.isEmpty(bundle.getString(EXTRA_USER_NAME))) ? bundle.getString(EXTRA_USER_NAME) : null;

/*else if (Intent.ACTION_VIEW.equalsIgnoreCase(intent.getAction())) {
if (intent.getData() != null) {
String param = intent.getData().getQueryParameter("id");
if (param != null && !param.equals("")) {
userName = param;
}
}
}*/

if (userName != null) {
//lets create a request and fill in the data when we have it
String url = "https://hacker-news.firebaseio.com/v0/user/" + userName + ".json";
Expand Down Expand Up @@ -128,8 +129,9 @@ public void onClick(View view) {
String month = getResources().getStringArray(R.array.months)[cal.get(Calendar.MONTH)];

metaTextview.setText("Karma: " + Utils.getThousandSeparatedString(karma) + " • Created: " + month + " " + cal.get(Calendar.DAY_OF_MONTH) + ", " + (cal.get(Calendar.YEAR)));

if (jsonObject.has("about") && !TextUtils.isEmpty(jsonObject.getString("about"))) {
aboutTextview.setHtml(jsonObject.getString("about"));
setLinkifiedText(Html.fromHtml(jsonObject.getString("about")).toString(), aboutTextview);
} else {
aboutTextview.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -183,4 +185,27 @@ public static void showUserDialog(FragmentManager fm, String name) {
userDialogFragment.show(fm, UserDialogFragment.TAG);
}

public void setLinkifiedText(String text, TextView textView) {
SpannableString spannableString = new SpannableString(text);

Pattern urlPattern = Pattern.compile("(https?://\\S+)");
Matcher urlMatcher = urlPattern.matcher(text);

while (urlMatcher.find()) {
String url = urlMatcher.group(1);

spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
Utils.openLinkMaybeHN(widget.getContext(), url);

}
}, urlMatcher.start(1), urlMatcher.end(1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

textView.setMovementMethod(LinkMovementMethod.getInstance());

textView.setText(spannableString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,8 @@ public boolean handleTag(boolean opening, String tag, Editable output, Attribute
end(output, A.class, false, new URLSpan(href) {
@Override
public void onClick(View widget) {
if (onClickATagListenerProvider != null) {
boolean clickConsumed =
onClickATagListenerProvider.provideTagClickListener()
.onClick(widget, spannedText, getURL());
if (onClickATagListenerProvider != null && widget != null) {
boolean clickConsumed = onClickATagListenerProvider.provideTagClickListener().onClick(widget, spannedText, getURL());
if (!clickConsumed) {
super.onClick(widget);
}
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,11 @@
app:title="Clear clicked stories"
app:icon="@drawable/ic_action_clear" />

<Preference
app:singleLineTitle="false"
app:key="pref_feedback"
app:title="Send feedback"
app:icon="@drawable/ic_action_feedback" />

<Preference
app:icon="@drawable/ic_action_source"
app:singleLineTitle="false"
app:key="pref_open_source"
app:title="GitHub"
app:summary="Harmonic is now open-source!" />
app:title="GitHub" />

<Preference
app:singleLineTitle="false"
Expand Down

0 comments on commit 259a36f

Please sign in to comment.