Skip to content

Commit

Permalink
Merge pull request #157 from flofriday/maintainance-refactor
Browse files Browse the repository at this point in the history
Refactor comments, imports and some code pieces
  • Loading branch information
SimonHalvdansson authored Apr 20, 2024
2 parents 0d76f0e + 37ff02e commit 9e5736c
Show file tree
Hide file tree
Showing 34 changed files with 347 additions and 479 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/gw/swipeback/SwipeBackLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class SwipeBackLayout extends ViewGroup {

private int leftOffset = 0;
private int topOffset = 0;
//important constant
// important constant
private float autoFinishedVelocityLimit = 3000f;

private int touchedEdge = ViewDragHelper.INVALID_POINTER;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.simon.harmonichackernews;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
ThemeUtils.setupTheme(this, swipeBack);

/*this is a long story. On CommentsActivity, the default theme is dependent on the android version.
For 24-29, we set SwipeBack as the defaul theme and do nothing more
For 24-29, we set SwipeBack as the default theme and do nothing more
For 30-33, we set AppTheme as the default and perhaps switch to SwipeBack if the user wants to, but in that case we indicate translucency manually
which makes it so that SwipeBack can peek to MainActivity
For 34+, translucent = true is set automatically in the onResume (after a delay) which makes the peek work
Expand Down Expand Up @@ -85,10 +85,10 @@ public void onSwitchView(boolean isAtWebView) {
}
}

//we only need to do the translucent setting on Android 14 and above as its purpose is to
//make the predictive back animation nice (when we peek back from a deeper activity,
// We only need to do the translucent setting on Android 14 and above as its purpose is to
// make the predictive back animation nice (when we peek back from a deeper activity,
// CommentsActivity cannot be transparent). The theme already sets the activity to translucent
//so when we animate in we are transparent which is important!
// so when we animate in we are transparent which is important!
@Override
protected void onResume() {
super.onResume();
Expand All @@ -102,7 +102,8 @@ public void run() {
}
}

//if we set translucency to false immediately onPause we can trigger animations by accident so we delay things a little
// If we set translucency to false immediately onPause we can trigger animations by accident so
// we delay things a little
@Override
protected void onPause() {
super.onPause();
Expand Down
176 changes: 90 additions & 86 deletions app/src/main/java/com/simon/harmonichackernews/CommentsFragment.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,68 +1,29 @@
package com.simon.harmonichackernews;

import static com.simon.harmonichackernews.SubmissionsActivity.KEY_USER;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.StringRequest;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputEditText;
import com.simon.harmonichackernews.adapters.CommentSearchAdapter;
import com.simon.harmonichackernews.data.Comment;
import com.simon.harmonichackernews.network.NetworkComponent;
import com.simon.harmonichackernews.utils.ThemeUtils;
import com.simon.harmonichackernews.utils.Utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.sufficientlysecure.htmltextview.HtmlTextView;
import org.sufficientlysecure.htmltextview.OnClickATagListener;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommentsSearchDialogFragment extends AppCompatDialogFragment {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public WindowInsetsAnimationCompat.BoundsCompat onStart(@NonNull WindowInsetsAni
backPressedCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
//This thing should only be enabled when we want to show the dialog, otherwise
//we just do the default back behavior (which is predictive back)
// This thing should only be enabled when we want to show the dialog, otherwise
// we just do the default back behavior (which is predictive back)
AlertDialog dialog = new MaterialAlertDialogBuilder(editText.getContext())
.setMessage(type == TYPE_POST ? "Discard post?" : "Discard comment?")
.setPositiveButton("Discard", new DialogInterface.OnClickListener() {
Expand All @@ -236,15 +236,11 @@ public void onClick(DialogInterface dialog, int whichButton) {
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//Make sure scrollview never takes up more than 1/3 of screen height
// Make sure scrollview never takes up more than 1/3 of screen height
ViewGroup.LayoutParams layout = replyingScrollView.getLayoutParams();
int dp160 = Utils.pxFromDpInt(getResources(), 160);
int screenHeightThird = Resources.getSystem().getDisplayMetrics().heightPixels / 3;
if (dp160 > screenHeightThird) {
layout.height = screenHeightThird;
} else {
layout.height = dp160;
}
layout.height = Math.min(dp160, screenHeightThird);
replyingScrollView.setLayoutParams(layout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
Expand All @@ -28,7 +23,6 @@
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.timepicker.MaterialTimePicker;
import com.google.android.material.timepicker.TimeFormat;
import com.gw.swipeback.SwipeBackLayout;
import com.simon.harmonichackernews.data.Bookmark;
import com.simon.harmonichackernews.utils.SettingsUtils;
import com.simon.harmonichackernews.utils.ThemeUtils;
Expand Down Expand Up @@ -74,10 +68,8 @@ public void handleOnBackPressed() {
getOnBackPressedDispatcher().addCallback(this, backPressedCallback);
backPressedCallback.setEnabled(false);

if (getIntent() != null) {
if (getIntent().getBooleanExtra(EXTRA_REQUEST_RESTART, false)) {
backPressedCallback.setEnabled(true);
}
if (getIntent() != null && getIntent().getBooleanExtra(EXTRA_REQUEST_RESTART, false)) {
backPressedCallback.setEnabled(true);
}
}

Expand All @@ -98,7 +90,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

findPreference("pref_default_story_type").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
if (getActivity() != null && getActivity() instanceof SettingsActivity) {
((SettingsActivity) getActivity()).backPressedCallback.setEnabled(true);
}
Expand All @@ -108,7 +100,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {

findPreference("pref_compact_view").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
changePrefStatus(findPreference("pref_show_points"), !(boolean) newValue);
changePrefStatus(findPreference("pref_show_comments_count"), !(boolean) newValue);
changePrefStatus(findPreference("pref_thumbnails"), !(boolean) newValue);
Expand All @@ -119,7 +111,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {

findPreference("pref_foldable_support").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
if (getActivity() != null && getActivity() instanceof SettingsActivity) {
((SettingsActivity) getActivity()).backPressedCallback.setEnabled(true);
}
Expand All @@ -136,7 +128,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {

findPreference("pref_transparent_status_bar").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
Intent intent = new Intent(getContext(), SettingsActivity.class);
intent.putExtra(EXTRA_REQUEST_RESTART, true);
requireContext().startActivity(intent);
Expand Down Expand Up @@ -198,7 +190,7 @@ public void onClick(View view) {

findPreference("pref_export_bookmarks").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {

String textToSave = SettingsUtils.readStringFromSharedPreferences(requireContext(), Utils.KEY_SHARED_PREFERENCES_BOOKMARKS);

Expand Down Expand Up @@ -226,7 +218,7 @@ public boolean onPreferenceClick(Preference preference) {

findPreference("pref_import_bookmarks").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
Expand All @@ -239,7 +231,7 @@ public boolean onPreferenceClick(Preference preference) {

findPreference("pref_clear_clicked_stories").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
Set<Integer> set = SettingsUtils.readIntSetFromSharedPreferences(requireContext(), Utils.KEY_SHARED_PREFERENCES_CLICKED_IDS);
int oldCount = set.size();

Expand All @@ -261,7 +253,7 @@ public boolean onPreferenceClick(Preference preference) {

findPreference("pref_about").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
startActivity(new Intent(getContext(), AboutActivity.class));

return false;
Expand All @@ -288,8 +280,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
String content = Utils.readFileContent(getContext(), data.getData());
ArrayList<Bookmark> bookmarks = Utils.loadBookmarks(true, content);
if (bookmarks.size() > 0) {
//save the new bookmarks
if (!bookmarks.isEmpty()) {
// save the new bookmarks
SettingsUtils.saveStringToSharedPreferences(getContext(), Utils.KEY_SHARED_PREFERENCES_BOOKMARKS, content);
Toast.makeText(getContext(), "Loaded " + bookmarks.size() + " bookmarks", Toast.LENGTH_SHORT).show();
} else {
Expand Down Expand Up @@ -321,7 +313,7 @@ private void updateTimedRangeSummary() {
int[] nighttimeHours = Utils.getNighttimeHours(getContext());

if (DateFormat.is24HourFormat(getContext())) {
findPreference("pref_theme_timed_range").setSummary((nighttimeHours[0] < 10 ? "0" : "") + nighttimeHours[0] + ":" + (nighttimeHours[1] < 10 ? "0" : "") + nighttimeHours[1] + " - " + (nighttimeHours[2] < 10 ? "0" : "") + nighttimeHours[2] + ":" + (nighttimeHours[3] < 10 ? "0" : "") + nighttimeHours[3]);
findPreference("pref_theme_timed_range").setSummary((nighttimeHours[0] < 10 ? "0" : "") + nighttimeHours[0] + ":" + (nighttimeHours[1] < 10 ? "0" : "") + nighttimeHours[1] + " - " + (nighttimeHours[2] < 10 ? "0" : "") + nighttimeHours[2] + ":" + (nighttimeHours[3] < 10 ? "0" : "") + nighttimeHours[3]);

} else {
SimpleDateFormat df = new SimpleDateFormat("h:mm a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

public class SplitPlaceholderActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeUtils.setupTheme(this);
setContentView(R.layout.activity_split_placeholder);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeUtils.setupTheme(this);
setContentView(R.layout.activity_split_placeholder);
}
}
Loading

0 comments on commit 9e5736c

Please sign in to comment.