Merge branch 'master' into 'master'

fix #1642

Closes #1642

See merge request fdroid/fdroidclient!768
This commit is contained in:
Hans-Christoph Steiner 2018-12-18 08:55:32 +00:00
commit fc27122dae
2 changed files with 25 additions and 32 deletions

View File

@ -74,7 +74,6 @@ public class RepoDetailsActivity extends AppCompatActivity {
private Repo repo; private Repo repo;
private long repoId; private long repoId;
private View repoView; private View repoView;
private String shareUrl; private String shareUrl;
/** /**
@ -83,9 +82,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
* Flex, there was a thing called "ViewStates" for exactly this. Wonder if * Flex, there was a thing called "ViewStates" for exactly this. Wonder if
* that exists in Android? * that exists in Android?
*/ */
private static void setMultipleViewVisibility(View parent, private static void setMultipleViewVisibility(View parent, int[] viewIds, int visibility) {
int[] viewIds,
int visibility) {
for (int viewId : viewIds) { for (int viewId : viewIds) {
parent.findViewById(viewId).setVisibility(visibility); parent.findViewById(viewId).setVisibility(visibility);
} }
@ -97,13 +94,13 @@ public class RepoDetailsActivity extends AppCompatActivity {
((FDroidApp) getApplication()).applyTheme(this); ((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.repodetails); setContentView(R.layout.activity_repo_details);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
repoView = findViewById(R.id.repoView); repoView = findViewById(R.id.repo_view);
repoId = getIntent().getLongExtra(ARG_REPO_ID, 0); repoId = getIntent().getLongExtra(ARG_REPO_ID, 0);
final String[] projection = { final String[] projection = {
@ -115,7 +112,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
}; };
repo = RepoProvider.Helper.findById(this, repoId, projection); repo = RepoProvider.Helper.findById(this, repoId, projection);
TextView inputUrl = (TextView) findViewById(R.id.input_repo_url); TextView inputUrl = findViewById(R.id.input_repo_url);
inputUrl.setText(repo.address); inputUrl.setText(repo.address);
if (repo.address.startsWith("content://")) { if (repo.address.startsWith("content://")) {
@ -170,8 +167,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
private void processIntent(Intent i) { private void processIntent(Intent i) {
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction())) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction())) {
Parcelable[] rawMsgs = Parcelable[] rawMsgs = i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage msg = (NdefMessage) rawMsgs[0]; NdefMessage msg = (NdefMessage) rawMsgs[0];
String url = new String(msg.getRecords()[0].getPayload()); String url = new String(msg.getRecords()[0].getPayload());
Utils.debugLog(TAG, "Got this URL: " + url); Utils.debugLog(TAG, "Got this URL: " + url);
@ -310,9 +306,9 @@ public class RepoDetailsActivity extends AppCompatActivity {
private void setupCredentials(View parent, Repo repo) { private void setupCredentials(View parent, Repo repo) {
TextView usernameLabel = (TextView) parent.findViewById(R.id.label_username); TextView usernameLabel = parent.findViewById(R.id.label_username);
TextView username = (TextView) parent.findViewById(R.id.text_username); TextView username = parent.findViewById(R.id.text_username);
Button changePassword = (Button) parent.findViewById(R.id.button_edit_credentials); Button changePassword = parent.findViewById(R.id.button_edit_credentials);
if (TextUtils.isEmpty(repo.username)) { if (TextUtils.isEmpty(repo.username)) {
usernameLabel.setVisibility(View.GONE); usernameLabel.setVisibility(View.GONE);
@ -328,13 +324,11 @@ public class RepoDetailsActivity extends AppCompatActivity {
} }
private void updateRepoView() { private void updateRepoView() {
if (repo.hasBeenUpdated()) { if (repo.hasBeenUpdated()) {
updateViewForExistingRepo(repoView); updateViewForExistingRepo(repoView);
} else { } else {
updateViewForNewRepo(repoView); updateViewForNewRepo(repoView);
} }
} }
private void updateViewForNewRepo(View repoView) { private void updateViewForNewRepo(View repoView) {
@ -346,34 +340,36 @@ public class RepoDetailsActivity extends AppCompatActivity {
setMultipleViewVisibility(repoView, SHOW_IF_EXISTS, View.VISIBLE); setMultipleViewVisibility(repoView, SHOW_IF_EXISTS, View.VISIBLE);
setMultipleViewVisibility(repoView, HIDE_IF_EXISTS, View.GONE); setMultipleViewVisibility(repoView, HIDE_IF_EXISTS, View.GONE);
TextView name = (TextView) repoView.findViewById(R.id.text_repo_name); TextView name = repoView.findViewById(R.id.text_repo_name);
TextView numApps = (TextView) repoView.findViewById(R.id.text_num_apps); TextView numApps = repoView.findViewById(R.id.text_num_apps);
TextView lastUpdated = (TextView) repoView.findViewById(R.id.text_last_update); TextView lastUpdated = repoView.findViewById(R.id.text_last_update);
if (repo.mirrors != null) { if (repo.mirrors != null) {
TextView officialMirrorsLabel = (TextView) repoView.findViewById(R.id.label_official_mirrors); TextView officialMirrorsLabel = repoView.findViewById(R.id.label_official_mirrors);
officialMirrorsLabel.setVisibility(View.VISIBLE); officialMirrorsLabel.setVisibility(View.VISIBLE);
TextView officialMirrorsText = (TextView) repoView.findViewById(R.id.text_official_mirrors); TextView officialMirrorsText = repoView.findViewById(R.id.text_official_mirrors);
officialMirrorsText.setVisibility(View.VISIBLE); officialMirrorsText.setVisibility(View.VISIBLE);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String url : repo.mirrors) { for (String url : repo.mirrors) {
builder.append(" "); builder.append(" ");
builder.append(url); builder.append(url);
builder.append('\n'); builder.append('\n');
} }
builder.setLength(Math.max(builder.length() - 1, 0));
officialMirrorsText.setText(builder.toString()); officialMirrorsText.setText(builder.toString());
} }
if (repo.userMirrors != null) { if (repo.userMirrors != null) {
TextView userMirrorsLabel = (TextView) repoView.findViewById(R.id.label_user_mirrors); TextView userMirrorsLabel = repoView.findViewById(R.id.label_user_mirrors);
userMirrorsLabel.setVisibility(View.VISIBLE); userMirrorsLabel.setVisibility(View.VISIBLE);
TextView userMirrorsText = (TextView) repoView.findViewById(R.id.text_user_mirrors); TextView userMirrorsText = repoView.findViewById(R.id.text_user_mirrors);
userMirrorsText.setVisibility(View.VISIBLE); userMirrorsText.setVisibility(View.VISIBLE);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String url : repo.userMirrors) { for (String url : repo.userMirrors) {
builder.append(" "); builder.append(" ");
builder.append(url); builder.append(url);
builder.append('\n'); builder.append('\n');
} }
builder.setLength(Math.max(builder.length() - 1, 0));
userMirrorsText.setText(builder.toString()); userMirrorsText.setText(builder.toString());
} }
@ -419,11 +415,10 @@ public class RepoDetailsActivity extends AppCompatActivity {
} }
public void showChangePasswordDialog(final View parentView) { public void showChangePasswordDialog(final View parentView) {
final View view = getLayoutInflater().inflate(R.layout.login, null); final View view = getLayoutInflater().inflate(R.layout.login, null);
final AlertDialog credentialsDialog = new AlertDialog.Builder(this).setView(view).create(); final AlertDialog credentialsDialog = new AlertDialog.Builder(this).setView(view).create();
final EditText nameInput = (EditText) view.findViewById(R.id.edit_name); final EditText nameInput = view.findViewById(R.id.edit_name);
final EditText passwordInput = (EditText) view.findViewById(R.id.edit_password); final EditText passwordInput = view.findViewById(R.id.edit_password);
nameInput.setText(repo.username); nameInput.setText(repo.username);
passwordInput.requestFocus(); passwordInput.requestFocus();

View File

@ -18,7 +18,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:id="@+id/repoView" android:id="@+id/repo_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
@ -85,8 +85,7 @@
<TextView <TextView
android:id="@+id/text_official_mirrors" android:id="@+id/text_official_mirrors"
style="@style/CaptionText" style="@style/BodyText"
android:textColor="@android:color/black"
android:visibility="gone" /> android:visibility="gone" />
<!-- mirrors added by the user --> <!-- mirrors added by the user -->
@ -98,8 +97,7 @@
<TextView <TextView
android:id="@+id/text_user_mirrors" android:id="@+id/text_user_mirrors"
style="@style/CaptionText" style="@style/BodyText"
android:textColor="@android:color/black"
android:visibility="gone" /> android:visibility="gone" />
<!-- The credentials used to access this repo (optional) --> <!-- The credentials used to access this repo (optional) -->