Added versions section
TODO: need string and icon
This commit is contained in:
parent
0898db3490
commit
56f0505d4a
@ -33,6 +33,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
|||||||
|
|
||||||
import org.fdroid.fdroid.data.App;
|
import org.fdroid.fdroid.data.App;
|
||||||
import org.fdroid.fdroid.data.AppProvider;
|
import org.fdroid.fdroid.data.AppProvider;
|
||||||
|
import org.fdroid.fdroid.views.ApkListAdapter;
|
||||||
import org.fdroid.fdroid.views.LinearLayoutManagerSnapHelper;
|
import org.fdroid.fdroid.views.LinearLayoutManagerSnapHelper;
|
||||||
import org.fdroid.fdroid.views.ScreenShotsRecyclerViewAdapter;
|
import org.fdroid.fdroid.views.ScreenShotsRecyclerViewAdapter;
|
||||||
|
|
||||||
@ -130,7 +132,7 @@ public class AppDetails2 extends AppCompatActivity {
|
|||||||
mItems.add(Integer.valueOf(VIEWTYPE_WHATS_NEW));
|
mItems.add(Integer.valueOf(VIEWTYPE_WHATS_NEW));
|
||||||
mItems.add(Integer.valueOf(VIEWTYPE_LINKS));
|
mItems.add(Integer.valueOf(VIEWTYPE_LINKS));
|
||||||
//mItems.add(Integer.valueOf(VIEWTYPE_PERMISSIONS));
|
//mItems.add(Integer.valueOf(VIEWTYPE_PERMISSIONS));
|
||||||
//mItems.add(Integer.valueOf(VIEWTYPE_VERSIONS));
|
mItems.add(Integer.valueOf(VIEWTYPE_VERSIONS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -154,7 +156,9 @@ public class AppDetails2 extends AppCompatActivity {
|
|||||||
} else if (viewType == VIEWTYPE_PERMISSIONS) {
|
} else if (viewType == VIEWTYPE_PERMISSIONS) {
|
||||||
|
|
||||||
} else if (viewType == VIEWTYPE_VERSIONS) {
|
} else if (viewType == VIEWTYPE_VERSIONS) {
|
||||||
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.app_details2_versions, parent, false);
|
||||||
|
return new VersionsViewHolder(view);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -318,6 +322,17 @@ public class AppDetails2 extends AppCompatActivity {
|
|||||||
if (!TextUtils.isEmpty(mApp.flattrID)) {
|
if (!TextUtils.isEmpty(mApp.flattrID)) {
|
||||||
addLinkItemView(vh.contentView, R.string.menu_flattr, R.drawable.ic_flattr, "https://flattr.com/thing/" + mApp.flattrID);
|
addLinkItemView(vh.contentView, R.string.menu_flattr, R.drawable.ic_flattr, "https://flattr.com/thing/" + mApp.flattrID);
|
||||||
}
|
}
|
||||||
|
} else if (viewType == VIEWTYPE_VERSIONS) {
|
||||||
|
final VersionsViewHolder vh = (VersionsViewHolder) holder;
|
||||||
|
vh.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean shouldBeVisible = (vh.contentView.getVisibility() != View.VISIBLE);
|
||||||
|
vh.contentView.setVisibility(shouldBeVisible ? View.VISIBLE : View.GONE);
|
||||||
|
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(vh.headerView, R.drawable.ic_source_code, 0, shouldBeVisible ? R.drawable.ic_expand_less_grey600 : R.drawable.ic_expand_more_grey600, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
vh.contentView.setAdapter(new ApkListAdapter(mContext, mApp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,6 +460,22 @@ public class AppDetails2 extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class VersionsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
final TextView headerView;
|
||||||
|
final ListView contentView;
|
||||||
|
|
||||||
|
VersionsViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
headerView = (TextView) view.findViewById(R.id.information);
|
||||||
|
contentView = (ListView) view.findViewById(R.id.lv_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " versions";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addLinkItemView(ViewGroup parent, int resIdText, int resIdDrawable, String url) {
|
private void addLinkItemView(ViewGroup parent, int resIdText, int resIdDrawable, String url) {
|
||||||
TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.app_details2_link_item, parent, false);
|
TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.app_details2_link_item, parent, false);
|
||||||
view.setTag(url);
|
view.setTag(url);
|
||||||
|
190
app/src/main/java/org/fdroid/fdroid/views/ApkListAdapter.java
Normal file
190
app/src/main/java/org/fdroid/fdroid/views/ApkListAdapter.java
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
package org.fdroid.fdroid.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.Utils;
|
||||||
|
import org.fdroid.fdroid.data.Apk;
|
||||||
|
import org.fdroid.fdroid.data.ApkProvider;
|
||||||
|
import org.fdroid.fdroid.data.App;
|
||||||
|
import org.fdroid.fdroid.data.InstalledAppProvider;
|
||||||
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ApkListAdapter extends ArrayAdapter<Apk> {
|
||||||
|
|
||||||
|
private static final String TAG = "ApkListAdapter";
|
||||||
|
|
||||||
|
private final LayoutInflater mInflater;
|
||||||
|
private final App mApp;
|
||||||
|
|
||||||
|
public ApkListAdapter(Context context, App app) {
|
||||||
|
super(context, 0);
|
||||||
|
mApp = app;
|
||||||
|
mInflater = (LayoutInflater) context.getSystemService(
|
||||||
|
Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
final List<Apk> apks = ApkProvider.Helper.findByPackageName(context, app.packageName);
|
||||||
|
for (final Apk apk : apks) {
|
||||||
|
if (apk.compatible || Preferences.get().showIncompatibleVersions()) {
|
||||||
|
add(apk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getInstalledStatus(final Apk apk) {
|
||||||
|
// Definitely not installed.
|
||||||
|
if (apk.versionCode != mApp.installedVersionCode) {
|
||||||
|
return getContext().getString(R.string.app_not_installed);
|
||||||
|
}
|
||||||
|
// Definitely installed this version.
|
||||||
|
if (apk.sig != null && apk.sig.equals(mApp.installedSig)) {
|
||||||
|
return getContext().getString(R.string.app_installed);
|
||||||
|
}
|
||||||
|
// Installed the same version, but from someplace else.
|
||||||
|
final String installerPkgName;
|
||||||
|
try {
|
||||||
|
installerPkgName = getContext().getPackageManager().getInstallerPackageName(mApp.packageName);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Log.w(TAG, "Application " + mApp.packageName + " is not installed anymore");
|
||||||
|
return getContext().getString(R.string.app_not_installed);
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(installerPkgName)) {
|
||||||
|
return getContext().getString(R.string.app_inst_unknown_source);
|
||||||
|
}
|
||||||
|
final String installerLabel = InstalledAppProvider
|
||||||
|
.getApplicationLabel(getContext(), installerPkgName);
|
||||||
|
return getContext().getString(R.string.app_inst_known_source, installerLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
|
java.text.DateFormat df = DateFormat.getDateFormat(getContext());
|
||||||
|
final Apk apk = getItem(position);
|
||||||
|
ViewHolder holder;
|
||||||
|
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = mInflater.inflate(R.layout.apklistitem, parent, false);
|
||||||
|
|
||||||
|
holder = new ViewHolder();
|
||||||
|
holder.version = (TextView) convertView.findViewById(R.id.version);
|
||||||
|
holder.status = (TextView) convertView.findViewById(R.id.status);
|
||||||
|
holder.repository = (TextView) convertView.findViewById(R.id.repository);
|
||||||
|
holder.size = (TextView) convertView.findViewById(R.id.size);
|
||||||
|
holder.api = (TextView) convertView.findViewById(R.id.api);
|
||||||
|
holder.incompatibleReasons = (TextView) convertView.findViewById(R.id.incompatible_reasons);
|
||||||
|
holder.buildtype = (TextView) convertView.findViewById(R.id.buildtype);
|
||||||
|
holder.added = (TextView) convertView.findViewById(R.id.added);
|
||||||
|
holder.nativecode = (TextView) convertView.findViewById(R.id.nativecode);
|
||||||
|
|
||||||
|
convertView.setTag(holder);
|
||||||
|
} else {
|
||||||
|
holder = (ViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.version.setText(getContext().getString(R.string.version)
|
||||||
|
+ " " + apk.versionName
|
||||||
|
+ (apk.versionCode == mApp.suggestedVersionCode ? " ☆" : ""));
|
||||||
|
|
||||||
|
holder.status.setText(getInstalledStatus(apk));
|
||||||
|
|
||||||
|
holder.repository.setText(getContext().getString(R.string.repo_provider,
|
||||||
|
RepoProvider.Helper.findById(getContext(), apk.repo).getName()));
|
||||||
|
|
||||||
|
if (apk.size > 0) {
|
||||||
|
holder.size.setText(Utils.getFriendlySize(apk.size));
|
||||||
|
holder.size.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.size.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Preferences.get().expertMode()) {
|
||||||
|
holder.api.setVisibility(View.GONE);
|
||||||
|
} else if (apk.minSdkVersion > 0 && apk.maxSdkVersion < Apk.SDK_VERSION_MAX_VALUE) {
|
||||||
|
holder.api.setText(getContext().getString(R.string.minsdk_up_to_maxsdk,
|
||||||
|
Utils.getAndroidVersionName(apk.minSdkVersion),
|
||||||
|
Utils.getAndroidVersionName(apk.maxSdkVersion)));
|
||||||
|
holder.api.setVisibility(View.VISIBLE);
|
||||||
|
} else if (apk.minSdkVersion > 0) {
|
||||||
|
holder.api.setText(getContext().getString(R.string.minsdk_or_later,
|
||||||
|
Utils.getAndroidVersionName(apk.minSdkVersion)));
|
||||||
|
holder.api.setVisibility(View.VISIBLE);
|
||||||
|
} else if (apk.maxSdkVersion > 0) {
|
||||||
|
holder.api.setText(getContext().getString(R.string.up_to_maxsdk,
|
||||||
|
Utils.getAndroidVersionName(apk.maxSdkVersion)));
|
||||||
|
holder.api.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apk.srcname != null) {
|
||||||
|
holder.buildtype.setText("source");
|
||||||
|
} else {
|
||||||
|
holder.buildtype.setText("bin");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apk.added != null) {
|
||||||
|
holder.added.setText(getContext().getString(R.string.added_on,
|
||||||
|
df.format(apk.added)));
|
||||||
|
holder.added.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.added.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Preferences.get().expertMode() && apk.nativecode != null) {
|
||||||
|
holder.nativecode.setText(TextUtils.join(" ", apk.nativecode));
|
||||||
|
holder.nativecode.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.nativecode.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apk.incompatibleReasons != null) {
|
||||||
|
holder.incompatibleReasons.setText(
|
||||||
|
getContext().getResources().getString(
|
||||||
|
R.string.requires_features,
|
||||||
|
TextUtils.join(", ", apk.incompatibleReasons)));
|
||||||
|
holder.incompatibleReasons.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
holder.incompatibleReasons.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable it all if it isn't compatible...
|
||||||
|
final View[] views = {
|
||||||
|
convertView,
|
||||||
|
holder.version,
|
||||||
|
holder.status,
|
||||||
|
holder.repository,
|
||||||
|
holder.size,
|
||||||
|
holder.api,
|
||||||
|
holder.buildtype,
|
||||||
|
holder.added,
|
||||||
|
holder.nativecode,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (final View v : views) {
|
||||||
|
v.setEnabled(apk.compatible);
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ViewHolder {
|
||||||
|
TextView version;
|
||||||
|
TextView status;
|
||||||
|
TextView repository;
|
||||||
|
TextView size;
|
||||||
|
TextView api;
|
||||||
|
TextView incompatibleReasons;
|
||||||
|
TextView buildtype;
|
||||||
|
TextView added;
|
||||||
|
TextView nativecode;
|
||||||
|
}
|
||||||
|
}
|
30
app/src/main/res/layout/app_details2_versions.xml
Normal file
30
app/src/main/res/layout/app_details2_versions.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/ll_information"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/details_activity_padding"
|
||||||
|
android:clickable="true"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:ignore="UnusedAttribute">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/information"
|
||||||
|
style="@style/AppDetailsSubheaderText"
|
||||||
|
android:text="@string/version"
|
||||||
|
android:drawableRight="@drawable/ic_expand_more_grey600"
|
||||||
|
android:drawableEnd="@drawable/ic_expand_more_grey600"
|
||||||
|
android:drawableLeft="@drawable/ic_website"
|
||||||
|
android:drawableStart="@drawable/ic_website" />
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/lv_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_marginLeft="@dimen/layout_horizontal_margin"
|
||||||
|
android:layout_marginStart="@dimen/layout_horizontal_margin"
|
||||||
|
android:visibility="gone">
|
||||||
|
</ListView>
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user