Skip to content

Commit 1da7704

Browse files
committed
refactor: re-use app icon header in about, welcome and help activity
1 parent 8880305 commit 1da7704

7 files changed

Lines changed: 97 additions & 97 deletions

File tree

app/src/main/java/com/github/libretube/ui/activities/AboutActivity.kt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.github.libretube.ui.activities
22

33
import android.annotation.SuppressLint
4-
import android.content.Intent
54
import android.content.res.Resources
65
import android.os.Build
76
import android.os.Bundle
87
import androidx.core.text.HtmlCompat
98
import androidx.core.text.parseAsHtml
10-
import com.github.libretube.BuildConfig
119
import com.github.libretube.R
1210
import com.github.libretube.databinding.ActivityAboutBinding
1311
import com.github.libretube.helpers.ClipboardHelper
@@ -31,19 +29,6 @@ class AboutActivity : BaseActivity() {
3129
onBackPressedDispatcher.onBackPressed()
3230
}
3331

34-
binding.appIcon.setOnClickListener {
35-
val sendIntent = Intent(Intent.ACTION_SEND)
36-
.putExtra(Intent.EXTRA_TEXT, GITHUB_URL)
37-
.setType("text/plain")
38-
startActivity(Intent.createChooser(sendIntent, null))
39-
}
40-
41-
val versionText = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
42-
binding.versionTv.text = versionText
43-
binding.versionCard.setOnClickListener {
44-
ClipboardHelper.save(this, text = versionText, notify = true)
45-
}
46-
4732
setupCard(binding.donate, DONATE_URL)
4833
setupCard(binding.website, WEBSITE_URL)
4934
setupCard(binding.piped, PIPED_GITHUB_URL)
@@ -126,7 +111,7 @@ class AboutActivity : BaseActivity() {
126111
companion object {
127112
const val DONATE_URL = "https://github.com/libre-tube/LibreTube#donate"
128113
private const val WEBSITE_URL = "https://libretube.dev"
129-
private const val GITHUB_URL = "https://github.com/libre-tube/LibreTube"
114+
const val GITHUB_URL = "https://github.com/libre-tube/LibreTube"
130115
private const val PIPED_GITHUB_URL = "https://github.com/TeamPiped/Piped"
131116
private const val WEBLATE_URL = "https://hosted.weblate.org/projects/libretube/libretube/"
132117
private const val LICENSE_URL = "https://gnu.org/"

app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MainActivity : BaseActivity() {
112112

113113
val isAppConfigured = PreferenceHelper.getBoolean(PreferenceKeys.LOCAL_FEED_EXTRACTION, false) ||
114114
PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, "").isNotEmpty()
115-
if (!isAppConfigured) {
115+
if (isAppConfigured) {
116116
val welcomeIntent = Intent(this, WelcomeActivity::class.java)
117117
startActivity(welcomeIntent)
118118
finish()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.libretube.ui.views
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.util.AttributeSet
6+
import android.view.LayoutInflater
7+
import android.widget.LinearLayout
8+
import com.github.libretube.BuildConfig
9+
import com.github.libretube.databinding.AppIconHeaderBinding
10+
import com.github.libretube.helpers.ClipboardHelper
11+
import com.github.libretube.ui.activities.AboutActivity.Companion.GITHUB_URL
12+
13+
class AppIconHeader(context: Context, attributeSet: AttributeSet? = null) :
14+
LinearLayout(context, attributeSet) {
15+
val binding = AppIconHeaderBinding.inflate(LayoutInflater.from(context), this, true)
16+
17+
init {
18+
val versionText = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
19+
binding.versionTv.text = versionText
20+
binding.versionCard.setOnClickListener {
21+
ClipboardHelper.save(context, text = versionText, notify = true)
22+
}
23+
24+
binding.appIcon.setOnClickListener {
25+
val sendIntent = Intent(Intent.ACTION_SEND)
26+
.putExtra(Intent.EXTRA_TEXT, GITHUB_URL)
27+
.setType("text/plain")
28+
29+
context.startActivity(Intent.createChooser(sendIntent, null))
30+
}
31+
}
32+
}

app/src/main/res/layout/activity_about.xml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent">
76

@@ -17,51 +16,9 @@
1716
app:navigationIcon="?homeAsUpIndicator"
1817
app:title="@string/about" />
1918

20-
<ImageView
21-
android:id="@+id/app_icon"
22-
android:layout_width="110dp"
23-
android:layout_height="110dp"
24-
android:layout_gravity="center"
25-
android:layout_marginTop="30dp"
26-
android:src="@drawable/ic_launcher_lockscreen"
27-
app:tint="?attr/colorSecondary"
28-
tools:ignore="ContentDescription" />
29-
30-
<RelativeLayout
19+
<com.github.libretube.ui.views.AppIconHeader
3120
android:layout_width="match_parent"
32-
android:layout_height="wrap_content"
33-
android:layout_gravity="center"
34-
android:layout_marginBottom="40dp">
35-
36-
<TextView
37-
android:id="@+id/app_name"
38-
android:layout_width="wrap_content"
39-
android:layout_height="wrap_content"
40-
android:layout_centerHorizontal="true"
41-
android:layout_marginTop="30dp"
42-
android:text="@string/app_name"
43-
android:textSize="24sp"
44-
android:textStyle="bold" />
45-
46-
<com.google.android.material.card.MaterialCardView
47-
android:id="@+id/version_card"
48-
style="@style/Widget.Material3.CardView.Elevated"
49-
android:layout_width="wrap_content"
50-
android:layout_height="wrap_content"
51-
android:layout_marginStart="-40dp"
52-
android:layout_toEndOf="@id/app_name">
53-
54-
<TextView
55-
android:id="@+id/version_tv"
56-
android:layout_width="wrap_content"
57-
android:layout_height="wrap_content"
58-
android:layout_marginHorizontal="6dp"
59-
android:layout_marginVertical="3dp"
60-
tools:text="1.0.0 (99)" />
61-
62-
</com.google.android.material.card.MaterialCardView>
63-
64-
</RelativeLayout>
21+
android:layout_height="wrap_content" />
6522

6623
<com.google.android.material.card.MaterialCardView
6724
android:id="@+id/donate"

app/src/main/res/layout/activity_help.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717
app:navigationIcon="?homeAsUpIndicator"
1818
app:title="@string/help" />
1919

20-
<ImageView
21-
android:layout_width="120dp"
22-
android:layout_height="120dp"
23-
android:layout_gravity="center"
24-
android:layout_marginTop="30dp"
25-
android:layout_marginBottom="40dp"
26-
android:src="@drawable/ic_launcher_lockscreen"
27-
app:tint="?attr/colorSecondary"
28-
tools:ignore="ContentDescription" />
20+
<com.github.libretube.ui.views.AppIconHeader
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content" />
2923

3024
<com.google.android.material.card.MaterialCardView
3125
android:id="@+id/faq"

app/src/main/res/layout/activity_welcome.xml

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,10 @@
1919
app:expandedTitleTextColor="@android:color/transparent"
2020
app:layout_scrollFlags="scroll|exitUntilCollapsed">
2121

22-
<LinearLayout
22+
<com.github.libretube.ui.views.AppIconHeader
23+
android:paddingTop="30dp"
2324
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
25-
android:orientation="vertical"
26-
android:paddingTop="50dp"
27-
android:paddingBottom="20dp">
28-
29-
<ImageView
30-
android:id="@+id/app_icon"
31-
android:layout_width="120dp"
32-
android:layout_height="120dp"
33-
android:layout_gravity="center"
34-
android:layout_marginBottom="15dp"
35-
android:src="@drawable/ic_launcher_lockscreen"
36-
app:tint="?attr/colorSecondary"
37-
tools:ignore="ContentDescription" />
38-
39-
<TextView
40-
android:layout_width="wrap_content"
41-
android:layout_height="wrap_content"
42-
android:layout_gravity="center"
43-
android:layout_marginHorizontal="20dp"
44-
android:layout_marginVertical="16dp"
45-
android:text="@string/welcome"
46-
android:textSize="18sp" />
47-
48-
</LinearLayout>
25+
android:layout_height="wrap_content" />
4926

5027
<com.google.android.material.appbar.MaterialToolbar
5128
android:id="@+id/toolbar"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
xmlns:tools="http://schemas.android.com/tools"
7+
android:orientation="vertical">
8+
9+
<ImageView
10+
android:id="@+id/app_icon"
11+
android:layout_width="110dp"
12+
android:layout_height="110dp"
13+
android:layout_gravity="center"
14+
android:layout_marginTop="30dp"
15+
android:src="@drawable/ic_launcher_lockscreen"
16+
app:tint="?attr/colorSecondary"
17+
tools:ignore="ContentDescription" />
18+
19+
<RelativeLayout
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_gravity="center"
23+
android:layout_marginBottom="40dp">
24+
25+
<TextView
26+
android:id="@+id/app_name"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_centerHorizontal="true"
30+
android:layout_marginTop="30dp"
31+
android:text="@string/app_name"
32+
android:textSize="24sp"
33+
android:textStyle="bold" />
34+
35+
<com.google.android.material.card.MaterialCardView
36+
android:id="@+id/version_card"
37+
style="@style/Widget.Material3.CardView.Elevated"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_marginStart="-40dp"
41+
android:layout_toEndOf="@id/app_name">
42+
43+
<TextView
44+
android:id="@+id/version_tv"
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:layout_marginHorizontal="6dp"
48+
android:layout_marginVertical="3dp"
49+
tools:text="1.0.0 (99)" />
50+
51+
</com.google.android.material.card.MaterialCardView>
52+
53+
</RelativeLayout>
54+
55+
</LinearLayout>

0 commit comments

Comments
 (0)