Improve layouts for apps
This commit is contained in:
parent
a6146c4de7
commit
c5edb94787
|
@ -19,6 +19,7 @@ class AppInfo {
|
|||
|
||||
private String domain;
|
||||
private android.content.pm.ApplicationInfo ApplicationInfo;
|
||||
private String title = null;
|
||||
|
||||
String getDomain() {
|
||||
return domain;
|
||||
|
@ -35,4 +36,12 @@ class AppInfo {
|
|||
void setApplicationInfo(android.content.pm.ApplicationInfo applicationInfo) {
|
||||
ApplicationInfo = applicationInfo;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import java.util.List;
|
|||
|
||||
public class AppInfoAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static final int LAYOUT_TITLE = 0;
|
||||
private static final int LAYOUT_INFO = 1;
|
||||
private List<AppInfo> appInfos;
|
||||
|
||||
AppInfoAdapter(List<AppInfo> appInfos) {
|
||||
|
@ -41,61 +43,81 @@ public class AppInfoAdapter extends RecyclerView.Adapter {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (appInfos.get(position).getTitle() == null) {
|
||||
return LAYOUT_INFO;
|
||||
} else {
|
||||
return LAYOUT_TITLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
|
||||
Context context = parent.getContext();
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_app_info, parent, false));
|
||||
if (getItemViewType(position) == LAYOUT_INFO) {
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_app_info, parent, false));
|
||||
} else {
|
||||
return new ViewHolderTitle(layoutInflater.inflate(R.layout.drawer_app_title, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
AppInfo appInfo = appInfos.get(viewHolder.getAdapterPosition());
|
||||
Context context = holder.itemView.getContext();
|
||||
holder.domain.setText(appInfo.getDomain());
|
||||
if (appInfo.getApplicationInfo() != null) {
|
||||
Drawable icon = appInfo.getApplicationInfo().loadIcon(context.getPackageManager());
|
||||
try {
|
||||
holder.app_icon.setImageDrawable(icon);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
holder.app_icon.setImageResource(R.drawable.ic_android);
|
||||
}
|
||||
String app_label = context.getPackageManager().getApplicationLabel(appInfo.getApplicationInfo()).toString();
|
||||
if (appInfo.getApplicationInfo().packageName.compareTo(BuildConfig.APPLICATION_ID) == 0) {
|
||||
holder.application_label.setText(app_label);
|
||||
holder.package_name.setVisibility(View.GONE);
|
||||
holder.valid.setImageResource(R.drawable.ic_check);
|
||||
holder.valid.setContentDescription(context.getString(R.string.valid));
|
||||
if (viewHolder.getItemViewType() == LAYOUT_INFO) {
|
||||
AppInfo appInfo = appInfos.get(viewHolder.getAdapterPosition());
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
Context context = holder.itemView.getContext();
|
||||
holder.domain.setText(appInfo.getDomain());
|
||||
if (appInfo.getApplicationInfo() != null) {
|
||||
Drawable icon = appInfo.getApplicationInfo().loadIcon(context.getPackageManager());
|
||||
try {
|
||||
holder.app_icon.setImageDrawable(icon);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
holder.app_icon.setImageResource(R.drawable.ic_android);
|
||||
}
|
||||
String app_label = context.getPackageManager().getApplicationLabel(appInfo.getApplicationInfo()).toString();
|
||||
if (appInfo.getApplicationInfo().packageName.compareTo(BuildConfig.APPLICATION_ID) == 0) {
|
||||
holder.application_label.setText(app_label);
|
||||
holder.package_name.setVisibility(View.GONE);
|
||||
holder.valid.setImageResource(R.drawable.ic_check);
|
||||
holder.valid.setContentDescription(context.getString(R.string.valid));
|
||||
} else {
|
||||
String package_name = appInfo.getApplicationInfo().packageName;
|
||||
holder.application_label.setText(app_label);
|
||||
holder.package_name.setVisibility(View.VISIBLE);
|
||||
holder.package_name.setText(String.format("(%s)", package_name));
|
||||
holder.valid.setImageResource(R.drawable.ic_error);
|
||||
holder.valid.setContentDescription(context.getString(R.string.error));
|
||||
}
|
||||
holder.main_container.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", appInfo.getApplicationInfo().packageName, null);
|
||||
intent.setData(uri);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
} else {
|
||||
String package_name = appInfo.getApplicationInfo().packageName;
|
||||
holder.application_label.setText(app_label);
|
||||
holder.package_name.setVisibility(View.VISIBLE);
|
||||
holder.package_name.setText(String.format("(%s)", package_name));
|
||||
holder.valid.setImageResource(R.drawable.ic_error);
|
||||
holder.valid.setContentDescription(context.getString(R.string.error));
|
||||
holder.application_label.setText(R.string.no_apps);
|
||||
holder.app_icon.setImageResource(R.drawable.ic_android);
|
||||
holder.valid.setContentDescription(context.getString(R.string.warning));
|
||||
holder.valid.setImageResource(R.drawable.ic_warning);
|
||||
holder.main_container.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("nitterizeme", "test");
|
||||
String url = "https://" + appInfo.getDomain();
|
||||
intent.setData(Uri.parse(url));
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
holder.main_container.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", appInfo.getApplicationInfo().packageName, null);
|
||||
intent.setData(uri);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
} else {
|
||||
holder.application_label.setText(R.string.no_apps);
|
||||
holder.app_icon.setImageResource(R.drawable.ic_android);
|
||||
holder.valid.setContentDescription(context.getString(R.string.warning));
|
||||
holder.valid.setImageResource(R.drawable.ic_warning);
|
||||
holder.main_container.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("nitterizeme", "test");
|
||||
String url = "https://" + appInfo.getDomain();
|
||||
intent.setData(Uri.parse(url));
|
||||
context.startActivity(intent);
|
||||
});
|
||||
ViewHolderTitle holder = (ViewHolderTitle) viewHolder;
|
||||
AppInfo appInfo = appInfos.get(viewHolder.getAdapterPosition());
|
||||
holder.title.setText(appInfo.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,5 +148,14 @@ public class AppInfoAdapter extends RecyclerView.Adapter {
|
|||
}
|
||||
}
|
||||
|
||||
static class ViewHolderTitle extends RecyclerView.ViewHolder {
|
||||
TextView title;
|
||||
|
||||
ViewHolderTitle(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -115,7 +115,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
"bibliogram.pussthecat.org"
|
||||
};
|
||||
|
||||
private AppInfoAdapter appInfoAdapter;
|
||||
private RecyclerView list_apps;
|
||||
private String[] domains;
|
||||
|
||||
|
@ -143,11 +142,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
domains[i] = host;
|
||||
i++;
|
||||
}
|
||||
for (String host : shortener_domains) {
|
||||
for (String host : instagram_domains) {
|
||||
domains[i] = host;
|
||||
i++;
|
||||
}
|
||||
for (String host : instagram_domains) {
|
||||
for (String host : shortener_domains) {
|
||||
domains[i] = host;
|
||||
i++;
|
||||
}
|
||||
|
@ -450,13 +449,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
Intent intent = new Intent(MainActivity.this, InstanceActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
ArrayList<AppInfo> appInfos = new ArrayList<>();
|
||||
for (String domain : domains) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setDomain(domain);
|
||||
appInfo.setApplicationInfo(getDefaultApp("https://" + domain + "/"));
|
||||
appInfos.add(appInfo);
|
||||
}
|
||||
|
||||
|
||||
enable_geo_uris.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
@ -522,9 +514,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
}
|
||||
);
|
||||
|
||||
appInfoAdapter = new AppInfoAdapter(appInfos);
|
||||
list_apps.setAdapter(appInfoAdapter);
|
||||
final LinearLayoutManager mLayoutManager;
|
||||
mLayoutManager = new LinearLayoutManager(MainActivity.this);
|
||||
list_apps.setLayoutManager(mLayoutManager);
|
||||
|
@ -582,14 +571,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (list_apps != null) {
|
||||
ArrayList<AppInfo> appInfos = new ArrayList<>();
|
||||
for (String domain : domains) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setDomain(domain);
|
||||
appInfo.setApplicationInfo(getDefaultApp("https://" + domain + "/"));
|
||||
appInfos.add(appInfo);
|
||||
}
|
||||
appInfoAdapter = new AppInfoAdapter(appInfos);
|
||||
ArrayList<AppInfo> appInfos = getAppInfo();
|
||||
AppInfoAdapter appInfoAdapter = new AppInfoAdapter(appInfos);
|
||||
list_apps.setAdapter(appInfoAdapter);
|
||||
}
|
||||
TextInputEditText nitter_instance = findViewById(R.id.nitter_instance);
|
||||
|
@ -618,4 +601,46 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private ArrayList<AppInfo> getAppInfo() {
|
||||
ArrayList<AppInfo> appInfos = new ArrayList<>();
|
||||
int j = 0;
|
||||
for (String domain : domains) {
|
||||
if (j == 0) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle("Twitter");
|
||||
appInfos.add(appInfo);
|
||||
} else if (j == twitter_domains.length) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle("YouTube");
|
||||
appInfos.add(appInfo);
|
||||
} else if (j == twitter_domains.length + youtube_domains.length) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle("Instagram");
|
||||
appInfos.add(appInfo);
|
||||
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle(getString(R.string.shortener_services));
|
||||
appInfos.add(appInfo);
|
||||
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle(getString(R.string.invidious_instances));
|
||||
appInfos.add(appInfo);
|
||||
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length + invidious_instances.length) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle(getString(R.string.nitter_instances));
|
||||
appInfos.add(appInfo);
|
||||
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length + invidious_instances.length + nitter_instances.length) {
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setTitle(getString(R.string.bibliogram_instances));
|
||||
appInfos.add(appInfo);
|
||||
}
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.setDomain(domain);
|
||||
appInfo.setApplicationInfo(getDefaultApp("https://" + domain + "/"));
|
||||
appInfos.add(appInfo);
|
||||
j++;
|
||||
}
|
||||
return appInfos;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -676,7 +676,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:minHeight="1800dp"
|
||||
android:minHeight="2000dp"
|
||||
android:overScrollMode="never"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
android:id="@+id/app_icon"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:contentDescription="@string/icon_of_the_app"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:padding="2dp"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
|
@ -34,6 +34,7 @@
|
|||
<string name="use_geo_uri">Use geo URI</string>
|
||||
<string name="how_to">How-to</string>
|
||||
<string name="shortened_detected">Shortened URL</string>
|
||||
<string name="shortener_services">Shortener services</string>
|
||||
<string name="open">Open</string>
|
||||
<string name="dismiss">Dismiss</string>
|
||||
<string name="resolving_shortened">Resolving shortened URL, please wait…</string>
|
||||
|
|
|
@ -2,6 +2,10 @@ Added:
|
|||
- Allow to redirect Invidious, Nitter and Bibliogram links to the preferred instances
|
||||
- Unshorten support for buff.ly
|
||||
|
||||
Changed:
|
||||
- Improve detection of apps opening by default links
|
||||
- Add titles above links for apps
|
||||
|
||||
Fixed:
|
||||
- Refresh issue when picking up another instance
|
||||
- Last Bibliogram instances not accessible
|
Loading…
Reference in New Issue