Compare commits

...

6 Commits

Author SHA1 Message Date
Balazs Toldi
2ea47cf7fd
Changed intent filter from www.hexbear.net to hexbear.net
Fixes #237
2024-01-04 11:06:55 +01:00
Balazs Toldi
6d23f4e13d
Merge remote-tracking branch 'origin/master' 2024-01-04 11:04:26 +01:00
Balazs Toldi
8a9102bc8a
Check the user token when opening the app 2024-01-04 11:03:29 +01:00
Balazs Toldi
40a9091b7d
Scaled and Controversial sort types 2024-01-03 14:28:28 +01:00
Balazs Toldi
af7148ce58
Removed IzzyOnDroid badge 2024-01-02 18:38:26 +01:00
Balazs Toldi
ff0bacff1d
Fix "share on local instance" option for post pages 2024-01-02 18:37:24 +01:00
13 changed files with 154 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

View File

@ -27,9 +27,6 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
<img src="./.assets/google-play-badge.png" height="80">
</a>
<a href="https://apt.izzysoft.de/fdroid/index/apk/eu.toldi.infinityforlemmy">
<img src="./.assets/IzzyOnDroid.png" height="80">
</a>
<a href="https://codeberg.org/Bazsalanszky/Eternity/releases/">
<img src="./.assets/codeberg.png" height="80">
</a>

View File

@ -323,7 +323,7 @@
<data android:host="feddit.de" />
<data android:host="lemmy.fmhy.ml" />
<data android:host="lemmy.ca" />
<data android:host="www.hexbear.net" />
<data android:host="hexbear.net" />
<data android:host="programming.dev" />
<data android:host="lemmy.dbzer0.com" />
<data android:host="lemmy.blahaj.zone" />

View File

@ -48,7 +48,10 @@ public class SortType {
TOP_SIX_MONTHS("TopSixMonths", "Top"),
TOP_NINE_MONTHS("TopNineMonths", "Top"),
TOP_YEAR("TopYear", "Top"),
TOP_ALL("TopAll", "Top");
TOP_ALL("TopAll", "Top"),
SCALED("Scaled", "Scaled"),
CONTROVERSIAL("Controversial", "Controversial");
public final String value;
public final String fullName;

View File

@ -67,6 +67,9 @@ public class LoginActivity extends BaseActivity {
private static final String ENABLE_DOM_STATE = "EDS";
private static final String IS_AGREE_TO_USER_AGGREMENT_STATE = "IATUAS";
public static final String EXTRA_INPUT_USERNAME = "INPUT_USERNAME";
public static final String EXTRA_INPUT_INSTANCE = "INPUT_INSTANCE";
@BindView(R.id.coordinator_layout_login_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_login_activity)
@ -149,6 +152,17 @@ public class LoginActivity extends BaseActivity {
isAgreeToUserAgreement = savedInstanceState.getBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE);
}
// Get username and instance from intent
Intent intent = getIntent();
String username_intent = intent.getStringExtra(EXTRA_INPUT_USERNAME);
String instance_intent = intent.getStringExtra(EXTRA_INPUT_INSTANCE);
if (username_intent != null) {
username_input.setText(username_intent);
}
if (instance_intent != null) {
instance_input.setText(instance_intent);
}
LemmyVerseFetchInstances.INSTANCE.fetchInstances(mLemmyVerseRetrofit, new FetchInstancesListener() {
@Override

View File

@ -248,6 +248,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private int fabOption;
private int inboxCount;
private boolean mBearerTokenUsed = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.installSplashScreen(this);
@ -340,7 +342,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mRetrofit.setAccessToken(mAccessToken);
mBearerTokenUsed = mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
@ -374,6 +376,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mRetrofit.setBaseURL(instancePreference);
this.recreate();
}
} else {
checkUserToken();
}
}
@ -1081,6 +1085,34 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
private void checkUserToken() {
if (mBearerTokenUsed) {
FetchUserData.validateAuthToken(mRetrofit.getRetrofit(), new FetchUserData.ValidateAuthTokenListener() {
@Override
public void onValidateAuthTokenSuccess() {
}
@Override
public void onValidateAuthTokenFailed() {
// Alert user that the token is invalid and they need to re-login
new MaterialAlertDialogBuilder(MainActivity.this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.token_expired)
.setMessage(R.string.token_expired_message)
.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
// Username without instance
String username = mAccountName.substring(0, mAccountQualifiedName.indexOf("@"));
intent.putExtra(LoginActivity.EXTRA_INPUT_USERNAME, username);
intent.putExtra(LoginActivity.EXTRA_INPUT_INSTANCE, mRetrofit.getBaseURL());
startActivity(intent);
})
.setCancelable(false)
.show();
}
});
}
}
private void loadUserData() {
if (!mFetchUserInfoSuccess) {
FetchUserData.fetchUnreadCount(mRetrofit.getRetrofit(), mAccessToken, new FetchUserData.FetchUserUnreadCountListener() {

View File

@ -346,7 +346,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mHideUpvoteRatio = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_UPVOTE_RATIO, false);
mHideTheNumberOfAwards = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
mHideSubredditAndUserPrefix = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mShareOnLocalInstance = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.SHARE_LINK_ON_LOCAL_INSTANCE, false);
mShareOnLocalInstance = sharedPreferences.getBoolean(SharedPreferencesUtils.SHARE_LINK_ON_LOCAL_INSTANCE, false);
mShowDisplayNames = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.POST_DETAIL_DISPLAY_NAME_INSTEAD_OF_USERNAME, true);
mHideTheNumberOfVotes = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mHideDownvotes = !currentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true);

View File

@ -66,6 +66,9 @@ public interface LemmyAPI {
@GET("api/v3/user/unread_count")
Call<MessageCount> userUnreadCount(@NonNull @Query("auth") String access_token);
@GET("api/v3/user/validate_auth")
Call<String> userValidateAuth();
@Headers("Content-Type: application/json")
@POST("api/v3/user/mention/mark_as_read")
Call<String> userMentionMarkAsRead(@Body ReadMessageDTO params);

View File

@ -43,6 +43,12 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
@BindView(R.id.top_type_text_view_sort_type_bottom_sheet_fragment)
TextView topTypeTextView;
@BindView(R.id.scaled_type_text_view_sort_type_bottom_sheet_fragment)
TextView scaledTypeTextView;
@BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment)
TextView controversialTypeTextView;
private BaseActivity activity;
public SortTypeBottomSheetFragment() {
@ -89,6 +95,10 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
oldTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(oldTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.TOP.fullName)) {
topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.SCALED.fullName)) {
scaledTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(scaledTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.CONTROVERSIAL.fullName)) {
controversialTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(controversialTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
}
hotTypeTextView.setOnClickListener(view -> {
@ -111,6 +121,16 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
dismiss();
});
scaledTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.SCALED));
dismiss();
});
controversialTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.CONTROVERSIAL));
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(rootView, activity.typeface);

View File

@ -107,6 +107,33 @@ public class FetchUserData {
});
}
public static void validateAuthToken(Retrofit retrofit, ValidateAuthTokenListener validateAuthTokenListener) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> validateAuthToken = api.userValidateAuth();
validateAuthToken.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
validateAuthTokenListener.onValidateAuthTokenSuccess();
} else {
validateAuthTokenListener.onValidateAuthTokenFailed();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
validateAuthTokenListener.onValidateAuthTokenFailed();
}
});
}
public interface ValidateAuthTokenListener {
void onValidateAuthTokenSuccess();
void onValidateAuthTokenFailed();
}
public interface FetchUserUnreadCountListener {
void onFetchUserUnreadCountSuccess(int unreadCount);

View File

@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="#000000"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M14,11V8c4.56,-0.58 8,-3.1 8,-6H2c0,2.9 3.44,5.42 8,6l0,3c-3.68,0.73 -8,3.61 -8,11h6v-2H4.13c0.93,-6.83 6.65,-7.2 7.87,-7.2s6.94,0.37 7.87,7.2H16v2h6C22,14.61 17.68,11.73 14,11zM12,22c-1.1,0 -2,-0.9 -2,-2c0,-0.55 0.22,-1.05 0.59,-1.41C11.39,17.79 16,16 16,16s-1.79,4.61 -2.59,5.41C13.05,21.78 12.55,22 12,22z" />
</vector>

View File

@ -87,6 +87,44 @@
android:textSize="?attr/font_default"
app:drawableTint="?attr/primaryTextColor" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/scaled_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableStart="@drawable/baseline_scale_24"
android:drawablePadding="48dp"
android:focusable="true"
android:fontFamily="?attr/font_family"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="32dp"
android:paddingBottom="16dp"
android:text="@string/sort_scaled"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
app:drawableTint="?attr/primaryTextColor" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/controversial_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableStart="@drawable/ic_controversial_24"
android:drawablePadding="48dp"
android:focusable="true"
android:fontFamily="?attr/font_family"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="32dp"
android:paddingBottom="16dp"
android:text="@string/sort_controversial"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
app:drawableTint="?attr/primaryTextColor" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/top_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"

View File

@ -1318,4 +1318,7 @@
<string name="original_app">The original Reddit app</string>
<string name="settings_credits_original_app_description">"Infinity was created by u/Hostilenemy "</string>
<string name="the_url_of_you_prefered_lemmy_instance_with_or_without_the_https_prefix">The URL of you prefered Lemmy instance with or without the https:// prefix</string>
<string name="sort_scaled">Scaled</string>
<string name="token_expired">Token Expired</string>
<string name="token_expired_message">"Your token has been expired. As Eternity does not store your password, you need to manually log back in! "</string>
</resources>