Skip to content

Commit

Permalink
A few fixes for the about view
Browse files Browse the repository at this point in the history
- Button doesn't seem to work on API 31, remove it and replace it with
  linked URL instead
- Fix a few layout bugs
- Remove unused imports
  • Loading branch information
dbrgn committed Apr 15, 2023
1 parent a2af990 commit 39e19cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package io.spaceapi.community.myhackerspace;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand All @@ -36,38 +27,14 @@ public AboutLayout(Context context, AttributeSet attrs, int defStyleAttr, int de
}

public void init() {
Button openRepoButton = findViewById(R.id.about_open_repo_button);
openRepoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TextView repository = (TextView)findViewById(R.id.about_repository);
String url = (String) repository.getText();
openWebPage(url);
}
});
TextView version = findViewById(R.id.about_version_text);
version.setText(BuildConfig.VERSION_NAME + " (" + Integer.toString(BuildConfig.VERSION_CODE) + ")");
}

public static AboutLayout create(Context context) {
// use xml layout, see https://stackoverflow.com/a/13889257
LayoutInflater layoutInflater = LayoutInflater.from(context);
AboutLayout about = (AboutLayout) layoutInflater.inflate(R.layout.about, null, false);
about.init();
return about;
}

public void openWebPage(String url) {
// from https://stackoverflow.com/a/43981160
Uri webpage = Uri.parse(url);

Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

if (intent.resolveActivity(getContext().getPackageManager()) != null) {
getContext().startActivity(intent);
}else{
//Page not found
}
}

}
13 changes: 6 additions & 7 deletions app/src/main/res/layout/about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<io.spaceapi.community.myhackerspace.AboutLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:orientation="vertical">

<LinearLayout
Expand All @@ -20,7 +22,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1.0.0" />
android:layout_marginStart="1sp"
android:text="{version}" />
</LinearLayout>

<LinearLayout
Expand All @@ -39,19 +42,15 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="1sp"
android:text="@string/about_license_text" />
</LinearLayout>

<TextView
android:id="@+id/about_repository"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/about_repository_url" />

<Button
android:id="@+id/about_open_repo_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/about_visit_repository" />

</io.spaceapi.community.myhackerspace.AboutLayout>

0 comments on commit 39e19cc

Please sign in to comment.