Add option to view instance of users/communities

This Commit adds an option to view the details of a users/communities instance, just like the instance info accessible from the navigation bar. #204
This commit is contained in:
Bazsalanszky 2024-07-18 11:09:22 +02:00
parent 42af7ee315
commit 06315c55ad
7 changed files with 64 additions and 6 deletions

View File

@ -50,9 +50,12 @@ import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import retrofit2.Retrofit;
public class InstanceInfoActivity extends BaseActivity {
public static final String INSTANCE_INFO_DOMAIN = "instance_info_domain";
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@ -93,6 +96,8 @@ public class InstanceInfoActivity extends BaseActivity {
private MarkwonAdapter mMarkwonAdapter;
private Markwon mPostDetailMarkwon;
private AdminRecyclerViewAdapter mAdminAdapter;
private Retrofit mRetrofit;
private String mInstanceDomain;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -105,6 +110,21 @@ public class InstanceInfoActivity extends BaseActivity {
setContentView(view);
setSupportActionBar(mInstanceInfoActivityViewBinding.toolbarInstanceInfoActivity);
if (savedInstanceState != null) {
mInstanceDomain = savedInstanceState.getString(INSTANCE_INFO_DOMAIN);
} else {
mInstanceDomain = getIntent().getStringExtra(INSTANCE_INFO_DOMAIN);
}
if (mInstanceDomain == null) {
mRetrofit = mRetorifitHolder.getRetrofit();
} else {
String originalBaseUrl = mRetorifitHolder.getBaseURL();
mRetorifitHolder.setBaseURL("https://" + mInstanceDomain);
mRetrofit = mRetorifitHolder.getRetrofit();
mRetorifitHolder.setBaseURL(originalBaseUrl);
}
setUpBindings();
applyCustomTheme();
@ -169,7 +189,7 @@ public class InstanceInfoActivity extends BaseActivity {
}
private void fetchInstanceInfo() {
FetchSiteInfo.fetchSiteInfo(mRetorifitHolder.getRetrofit(), null, new FetchSiteInfo.FetchSiteInfoListener() {
FetchSiteInfo.fetchSiteInfo(mRetrofit, null, new FetchSiteInfo.FetchSiteInfoListener() {
@Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo, MyUserInfo myUserInfo) {
mLoadingConstraintLayout.setVisibility(View.GONE);
@ -264,4 +284,16 @@ public class InstanceInfoActivity extends BaseActivity {
}
return false;
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(INSTANCE_INFO_DOMAIN, mInstanceDomain);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mInstanceDomain = savedInstanceState.getString(INSTANCE_INFO_DOMAIN);
}
}

View File

@ -1321,6 +1321,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} else if (itemId == R.id.action_add_to_home_screen_view_subreddit_detail_activity) {
Bitmap icon = subredditIconBitmap == null ? decodeResource(getResources(), R.drawable.subreddit_default_icon) : subredditIconBitmap;
return ShortcutManager.requestPinShortcut(this, qualifiedName, icon);
} else if (itemId == R.id.action_view_instance_view_subreddit_detail_activity) {
String instance = communityData.getActorId().split("/")[2];
Intent intent = new Intent(this,InstanceInfoActivity.class);
intent.putExtra(InstanceInfoActivity.INSTANCE_INFO_DOMAIN, instance);
startActivity(intent);
}
return false;
}

View File

@ -1323,6 +1323,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
Toast.makeText(ViewUserDetailActivity.this, R.string.unblock_user_failed, Toast.LENGTH_SHORT).show();
}
});
} else if (itemId == R.id.action_view_instance_view_user_detail_activity) {
String instance = mUserData.getActorId().split("/")[2];
Intent intent = new Intent(this, InstanceInfoActivity.class);
intent.putExtra(InstanceInfoActivity.INSTANCE_INFO_DOMAIN, instance);
startActivity(intent);
}
return false;
}

View File

@ -1,5 +1,7 @@
package eu.toldi.infinityforlemmy.adapters;
import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -20,6 +22,7 @@ import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.activities.InstanceInfoActivity;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@ -145,9 +148,16 @@ public class BlockedInstancesRecyclerViewAdapter extends RecyclerView.Adapter<Re
iconUrl = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition() - offset).getIcon();
}
if (itemClickListener == null) {
// TODO: 2020-07-29 Add instance view page
}
((InstanceViewHolder) viewHolder).itemView.setOnClickListener(view -> {
if (mBlockedInstanceData != null) {
BlockedInstanceData instanceData = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition());
Intent intent = new Intent(mActivity, InstanceInfoActivity.class);
intent.putExtra(InstanceInfoActivity.INSTANCE_INFO_DOMAIN, instanceData.getDomain());
mActivity.startActivity(intent);
}
});
if (iconUrl == null || iconUrl.equals("")) {
((InstanceViewHolder) viewHolder).iconGifImageView.setVisibility(View.GONE);

View File

@ -60,9 +60,9 @@
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_wiki_view_subreddit_detail_activity"
android:id="@+id/action_view_instance_view_subreddit_detail_activity"
android:orderInCategory="9"
android:title="@string/action_go_to_wiki"
android:title="@string/view_instance"
app:showAsAction="never" />
<item

View File

@ -60,4 +60,9 @@
android:id="@+id/action_edit_profile_view_user_detail_activity"
android:orderInCategory="11"
android:title="@string/action_edit_profile" />
<item
android:id="@+id/action_view_instance_view_user_detail_activity"
android:orderInCategory="12"
android:title="@string/view_instance" />
</menu>

View File

@ -1325,4 +1325,5 @@
<string name="sort_new_comments">New Comments</string>
<string name="instances">Instances</string>
<string name="no_blocked_instances">No blocked instances</string>
<string name="view_instance">View Instance</string>
</resources>