Skip to content

Commit 4580216

Browse files
committed
-버전 체크 기능 추가
-1.6 업데이트
1 parent 7bee451 commit 4580216

File tree

5 files changed

+162
-2
lines changed

5 files changed

+162
-2
lines changed

Source/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.ksi.alltv"
77
minSdkVersion 23
88
targetSdkVersion 26
9-
versionCode 5
10-
versionName "1.5"
9+
versionCode 6
10+
versionName "1.6"
1111
}
1212
buildTypes {
1313
release {

Source/app/src/main/java/com/ksi/alltv/MainFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class MainFragment extends BrowseSupportFragment implements FetchChannelR
6868

6969
private Boolean beStarted = false;
7070

71+
private VersionChecker mVersionChecker;
72+
7173
@Override
7274
public void onActivityCreated(Bundle savedInstanceState) {
7375
super.onActivityCreated(savedInstanceState);
@@ -127,6 +129,11 @@ private void initOnCreated() {
127129

128130
mChannelResultReceiver = new FetchChannelResultReceiver(mHandler);
129131
mChannelResultReceiver.setReceiver(this);
132+
133+
//Version Check
134+
mVersionChecker = new VersionChecker(getActivity());
135+
mVersionChecker.setcheckJsonUrl(getStringById(R.string.UPDATE_JSON_URL));
136+
mVersionChecker.check();
130137
}
131138

132139
@Override
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019 PYTHONKOR
5+
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.ksi.alltv;
26+
27+
import android.app.AlertDialog;
28+
import android.app.Dialog;
29+
import android.content.Context;
30+
import android.content.pm.PackageInfo;
31+
import android.content.pm.PackageManager;
32+
import android.os.AsyncTask;
33+
34+
import com.google.gson.JsonObject;
35+
import com.google.gson.JsonParser;
36+
37+
38+
public class VersionChecker {
39+
40+
private Context mContext;
41+
private String mPackageName, mUpdateJsonUrl, mCurrentVersion, mPatchedVersion;
42+
private Dialog mDialog;
43+
private String mOkButtonText;
44+
private String mDialogMessageText;
45+
private String mDialogTitleText;
46+
47+
public VersionChecker(Context activity) {
48+
this.mContext = activity;
49+
this.getCurrentVersion();
50+
}
51+
52+
public void check() {
53+
new GetLatestVersion().execute();
54+
}
55+
56+
public void setokButtonText(String okButtonText) {
57+
this.mOkButtonText = okButtonText;
58+
}
59+
60+
public void setmDialogMessageText(String mDialogMessageText) {
61+
this.mDialogMessageText = mDialogMessageText;
62+
}
63+
64+
public void setmDialogTitleText(String mDialogTitleText) {
65+
this.mDialogTitleText = mDialogTitleText;
66+
}
67+
68+
public void setcheckJsonUrl(String checkUrl) {
69+
this.mUpdateJsonUrl = checkUrl;
70+
}
71+
72+
public final String getAppDataString(int resourceId) {
73+
return mContext.getResources().getString(resourceId);
74+
}
75+
76+
private void getCurrentVersion() {
77+
PackageManager pm = mContext.getPackageManager();
78+
PackageInfo pInfo;
79+
80+
try {
81+
mPackageName = mContext.getPackageName();
82+
pInfo = pm.getPackageInfo(mContext.getPackageName(), 0);
83+
mCurrentVersion = pInfo.versionName;
84+
} catch (PackageManager.NameNotFoundException e1) {
85+
e1.printStackTrace();
86+
}
87+
}
88+
89+
private class GetLatestVersion extends AsyncTask<String, String, Integer> {
90+
91+
@Override
92+
protected void onPreExecute() {
93+
super.onPreExecute();
94+
}
95+
96+
@Override
97+
protected Integer doInBackground(String... params) {
98+
try {
99+
100+
String resultJson = HttpRequest.get(mUpdateJsonUrl, true).body();
101+
102+
JsonParser jParser = new JsonParser();
103+
JsonObject jObj = jParser.parse(resultJson).getAsJsonObject();
104+
105+
mPatchedVersion = jObj.get(getAppDataString(R.string.PATCHED_STR)).getAsString();
106+
107+
} catch (Exception e) {
108+
e.printStackTrace();
109+
}
110+
111+
return 0;
112+
}
113+
114+
@Override
115+
protected void onPostExecute(Integer jsonObject) {
116+
if (mPatchedVersion != null && mPatchedVersion.length() > 0) {
117+
if (!mCurrentVersion.equalsIgnoreCase(mPatchedVersion)) {
118+
showUpdateDialog();
119+
}
120+
}
121+
122+
super.onPostExecute(jsonObject);
123+
}
124+
}
125+
126+
private void showUpdateDialog() {
127+
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
128+
129+
builder.setTitle(mDialogTitleText != null ?
130+
mDialogTitleText : getAppDataString(R.string.update_title_str));
131+
132+
builder.setMessage(mDialogMessageText != null ?
133+
mDialogMessageText : getAppDataString(R.string.update_version_str));
134+
135+
builder.setPositiveButton(mOkButtonText != null ?
136+
mOkButtonText : getAppDataString(R.string.ok_str), (dialog, which) -> {
137+
try {
138+
dialog.dismiss();
139+
} catch (Exception e) {
140+
e.printStackTrace();
141+
dialog.dismiss();
142+
}
143+
});
144+
145+
mDialog = builder.show();
146+
}
147+
}

Source/app/src/main/res/values/appdata.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@
8383
<string name="ISRADIO_TAG">isRadio</string>
8484
<string name="YES_STR">Y</string>
8585
<string name="RETURNCODE_TAG">returnCode</string>
86+
<string name="UPDATE_JSON_URL">https://raw.githubusercontent.com/PYTHONKOR/alltv/master/Source/version.json</string>
87+
<string name="PATCHED_STR">PatchedVersion</string>
8688

8789
<integer name="GRID_ITEM_WIDTH">300</integer>
8890
<integer name="GRID_ITEM_HEIGHT">200</integer>
8991
<integer name="POOQ_SUCCESS_CODE">200</integer>
92+
9093
</resources>

Source/app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@
3636
<string name="oksusu_login_fail">옥수수 로그인에 실패했습니다.</string>
3737
<string name="pooq_login_fail">POOQ 로그인에 실패했습니다.</string>
3838
<string name="version_str">버전 :</string>
39+
<string name="update_title_str">업데이트 안내</string>
40+
<string name="update_version_str">새로운 버전의 업데이트가 있습니다. Github에서 확인해 보세요.</string>
41+
<string name="ok_str">확인</string>
3942
</resources>

0 commit comments

Comments
 (0)