Skip to content

Commit 5886771

Browse files
committed
add new button checkUpdate
1 parent 091392a commit 5886771

File tree

10 files changed

+236
-19
lines changed

10 files changed

+236
-19
lines changed

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ dependencies {
9494
implementation("net.peanuuutz.tomlkt:tomlkt:0.3.7")
9595
//implementation("me.gujun.android:span:1.7")
9696
implementation("com.otaliastudios.opengl:egloo:0.6.1")
97+
implementation("net.swiftzer.semver:semver:2.1.0")
9798

9899
implementation(libs.androidx.core.ktx)
99100
implementation(libs.androidx.appcompat)

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:maxSdkVersion="28" />
88
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
99
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
10+
<uses-permission android:name="android.permission.INTERNET" />
1011

1112
<application
1213
android:allowBackup="true"
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright 2025 Toni500git
3+
*
4+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5+
* following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8+
* disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11+
* disclaimer in the documentation and/or other materials provided with the distribution.
12+
*
13+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
17+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*
24+
*/
25+
26+
package org.toni.customfetch_android
27+
28+
import android.content.Intent
29+
import android.graphics.Color
30+
import android.net.Uri
31+
import android.os.Bundle
32+
import android.view.LayoutInflater
33+
import android.view.View
34+
import android.view.ViewGroup
35+
import androidx.fragment.app.Fragment
36+
import kotlinx.coroutines.CoroutineScope
37+
import kotlinx.coroutines.Dispatchers
38+
import kotlinx.coroutines.launch
39+
import kotlinx.coroutines.withContext
40+
import org.json.JSONException
41+
import org.json.JSONObject
42+
import org.toni.customfetch_android.databinding.CheckUpdateFragmentBinding
43+
import java.io.BufferedReader
44+
import java.io.IOException
45+
import java.io.InputStreamReader
46+
import java.net.HttpURLConnection
47+
import java.net.URL
48+
import net.swiftzer.semver.SemVer
49+
50+
// original: https://stackoverflow.com/a/16612247
51+
class JSONParser {
52+
suspend fun getJSONFromUrl(url: String): JSONObject? = withContext(Dispatchers.IO) {
53+
try {
54+
val connection = URL(url).openConnection() as HttpURLConnection
55+
connection.setRequestProperty("User-Agent", USER_AGENT)
56+
57+
if (connection.responseCode == 200) {
58+
val reader = BufferedReader(InputStreamReader(connection.inputStream))
59+
val buffer = StringBuilder(4096)
60+
var line: String?
61+
62+
while (reader.readLine().also { line = it } != null) {
63+
buffer.append(line)
64+
}
65+
reader.close()
66+
67+
return@withContext JSONObject(buffer.toString())
68+
}
69+
} catch (_: IOException) {
70+
} catch (_: JSONException) {
71+
}
72+
return@withContext null
73+
}
74+
75+
companion object {
76+
private const val USER_AGENT =
77+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31"
78+
}
79+
}
80+
81+
class CheckUpdateFragment : Fragment() {
82+
83+
private var _binding: CheckUpdateFragmentBinding? = null
84+
// This property is only valid between onCreateView and
85+
// onDestroyView.
86+
private val binding get() = _binding!!
87+
88+
override fun onCreateView(
89+
inflater: LayoutInflater, container: ViewGroup?,
90+
savedInstanceState: Bundle?
91+
): View {
92+
_binding = CheckUpdateFragmentBinding.inflate(inflater, container, false)
93+
binding.toolbar.apply {
94+
setNavigationIcon(R.drawable.arrow_back)
95+
setNavigationOnClickListener { _ ->
96+
requireActivity().supportFragmentManager.popBackStack()
97+
}
98+
}
99+
binding.titleResult.setTextColor(Color.YELLOW)
100+
binding.titleResult.text = "Checking..."
101+
102+
return binding.root
103+
}
104+
105+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
106+
super.onViewCreated(view, savedInstanceState)
107+
108+
CoroutineScope(Dispatchers.Main).launch {
109+
val json = JSONParser().getJSONFromUrl("https://api.github.com/repos/Toni500github/customfetch-android-app/releases/latest")
110+
try {
111+
val release = json?.getString("tag_name") ?: ""
112+
val semver = if (release[0] == 'v') SemVer.parse(release.substring(1)) else SemVer.parse(release)
113+
if (semver < SemVer.parse(BuildConfig.VERSION_NAME)) {
114+
binding.titleResult.setTextColor(Color.GREEN)
115+
binding.titleResult.text = "New Release Available"
116+
binding.githubRelease.visibility = View.VISIBLE
117+
binding.githubRelease.setOnClickListener {
118+
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/Toni500github/customfetch-android-app/releases/latest")))
119+
}
120+
} else {
121+
binding.titleResult.setTextColor(Color.WHITE)
122+
binding.titleResult.text = "Already Up-to-date"
123+
}
124+
} catch (e: IllegalArgumentException) {
125+
binding.titleResult.setTextColor(Color.YELLOW)
126+
binding.titleResult.text = "Could not find a new release, yet"
127+
}
128+
}
129+
}
130+
131+
override fun onDestroyView() {
132+
super.onDestroyView()
133+
_binding = null
134+
}
135+
}

app/src/main/java/org/toni/customfetch_android/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class MainActivity : AppCompatActivity() {
104104
startActivityForResult(intent, TEST_CONFIG_FILE_RC)
105105
}
106106

107+
binding.checkUpdate.setOnTouchListener { view, event -> startAnimation(view, event) }
108+
binding.checkUpdate.setOnClickListener { setFragment(CheckUpdateFragment()) }
109+
107110
binding.aboutMe.setOnTouchListener { view, event -> startAnimation(view, event) }
108111
binding.aboutMe.setOnClickListener { setFragment(AboutMeFragment()) }
109112

@@ -144,6 +147,7 @@ class MainActivity : AppCompatActivity() {
144147
}
145148
}
146149

150+
@Deprecated("Deprecated in Java")
147151
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
148152
super.onActivityResult(requestCode, resultCode, data)
149153
if (resultCode == RESULT_OK && data != null && data.data != null) {

app/src/main/java/org/toni/customfetch_android/TestConfigFragment.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ package org.toni.customfetch_android
2727

2828
import android.graphics.Color
2929
import android.os.Bundle
30-
import android.text.TextPaint
3130
import android.view.LayoutInflater
3231
import android.view.View
3332
import android.view.ViewGroup
34-
import androidx.appcompat.app.AppCompatActivity
3533
import androidx.fragment.app.Fragment
3634
import org.toni.customfetch_android.databinding.TestConfigFragmentBinding
37-
import org.toni.customfetch_android.widget.getParsedContent
3835
import org.toni.customfetch_android_lib.mainRender
39-
import org.toni.customfetch_android_lib.mainRenderStr
4036

4137
class TestConfigFragment : Fragment() {
4238

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<TextView
4242
android:layout_width="wrap_content"
4343
android:layout_height="wrap_content"
44-
android:text="Test config file"
44+
android:text="Test Config File"
4545
android:textColor="@color/text"
4646
android:textSize="16sp" />
4747

@@ -97,7 +97,7 @@
9797
</LinearLayout>
9898

9999
<LinearLayout
100-
android:id="@+id/aboutMe"
100+
android:id="@+id/checkUpdate"
101101
android:layout_width="match_parent"
102102
android:layout_height="wrap_content"
103103
android:orientation="vertical"
@@ -112,14 +112,43 @@
112112
<TextView
113113
android:layout_width="wrap_content"
114114
android:layout_height="wrap_content"
115-
android:text="About me"
115+
android:text="Check Update"
116+
android:textColor="@color/text"
117+
android:textSize="16sp" />
118+
119+
<TextView
120+
android:layout_width="wrap_content"
121+
android:layout_height="wrap_content"
122+
android:text="Check an update for the app"
123+
android:textColor="@color/subText"
124+
android:textSize="14sp"
125+
android:layout_marginTop="8dp" />
126+
</LinearLayout>
127+
128+
<LinearLayout
129+
android:id="@+id/aboutMe"
130+
android:layout_width="match_parent"
131+
android:layout_height="wrap_content"
132+
android:orientation="vertical"
133+
android:background="@drawable/round_border"
134+
android:padding="24dp"
135+
android:layout_marginTop="24dp"
136+
android:layout_margin="20dp"
137+
app:layout_constraintTop_toBottomOf="@id/checkUpdate"
138+
app:layout_constraintStart_toStartOf="parent"
139+
app:layout_constraintEnd_toEndOf="parent">
140+
141+
<TextView
142+
android:layout_width="wrap_content"
143+
android:layout_height="wrap_content"
144+
android:text="About Me"
116145
android:textColor="@color/text"
117146
android:textSize="16sp" />
118147

119148
<TextView
120149
android:layout_width="wrap_content"
121150
android:layout_height="wrap_content"
122-
android:text="About me and customfetch"
151+
android:text="Credits"
123152
android:textColor="@color/subText"
124153
android:textSize="14sp"
125154
android:layout_marginTop="8dp" />
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@color/background" >
8+
9+
<androidx.appcompat.widget.Toolbar
10+
android:id="@+id/toolbar"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:background="@color/toolBar"
14+
android:popupTheme="?attr/actionBarPopupTheme"
15+
android:animateLayoutChanges="true"
16+
app:titleTextColor="#ffFFff"
17+
app:title="Check Update" />
18+
19+
<LinearLayout
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"
22+
android:orientation="vertical"
23+
android:gravity="center" >
24+
25+
<TextView
26+
android:id="@+id/titleResult"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_marginBottom="20dp"/>
30+
31+
<LinearLayout
32+
android:id="@+id/githubRelease"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:orientation="vertical"
36+
android:background="@drawable/round_border"
37+
android:padding="24dp"
38+
android:gravity="center"
39+
android:layout_gravity="center"
40+
android:layout_marginTop="24dp"
41+
android:layout_margin="20dp"
42+
app:layout_constraintTop_toBottomOf="@id/widgetSettings"
43+
app:layout_constraintStart_toStartOf="parent"
44+
app:layout_constraintEnd_toEndOf="parent"
45+
android:visibility="gone">
46+
47+
<TextView
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
android:text="Update app"
51+
android:textColor="@color/text"
52+
android:textSize="16sp" />
53+
</LinearLayout>
54+
55+
</LinearLayout>
56+
57+
</LinearLayout>

gradle/libs.versions.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ agp = "8.7.2"
33
colorpickerpref = "1.1.0"
44
colorpickerview = "2.3.0"
55
expandablelayout = "2.9.2"
6-
htmlspanner = "0.4"
7-
kotlin = "1.9.24"
6+
kotlin = "2.1.10"
87
coreKtx = "1.15.0"
9-
junit = "4.13.2"
10-
junitVersion = "1.2.1"
11-
espressoCore = "3.6.1"
128
appcompat = "1.7.0"
139
material = "1.12.0"
1410
constraintlayout = "2.2.0"
@@ -22,10 +18,6 @@ androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref =
2218
colorpickerpref = { module = "com.jaredrummler:colorpicker", version.ref = "colorpickerpref" }
2319
colorpickerview = { module = "com.github.skydoves:colorpickerview", version.ref = "colorpickerview" }
2420
expandablelayout = { module = "com.github.cachapa:ExpandableLayout", version.ref = "expandablelayout" }
25-
htmlspanner = { module = "com.github.NightWhistler:HtmlSpanner", version.ref = "htmlspanner" }
26-
junit = { group = "junit", name = "junit", version.ref = "junit" }
27-
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
28-
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
2921
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
3022
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
3123
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

settings.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
pluginManagement {
2+
plugins {
3+
id("org.jetbrains.kotlin.android") version "2.1.10"
4+
}
25
repositories {
36
google {
47
content {
@@ -7,7 +10,6 @@ pluginManagement {
710
includeGroupByRegex("androidx.*")
811
}
912
}
10-
maven { url = uri("https://jitpack.io") }
1113
mavenCentral()
1214
gradlePluginPortal()
1315
}

0 commit comments

Comments
 (0)