Skip to content

Commit ba61ce0

Browse files
committed
1.3.5
1 parent 58d1258 commit ba61ce0

9 files changed

Lines changed: 145 additions & 60 deletions

File tree

app/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'com.google.gms.google-services'
32
apply plugin: 'io.fabric'
43

54
android {
@@ -10,8 +9,8 @@ android {
109
applicationId "io.github.javiewer"
1110
minSdkVersion 15
1211
targetSdkVersion 27
13-
versionCode 11
14-
versionName "1.3.4"
12+
versionCode 12
13+
versionName "1.3.5"
1514

1615
}
1716
buildTypes {
@@ -58,7 +57,7 @@ dependencies {
5857
compile 'jp.wasabeef:recyclerview-animators:2.2.6'
5958
//Firebase
6059
//compile 'com.google.firebase:firebase-crash:10.0.1'
61-
compile 'com.google.firebase:firebase-auth:10.0.1'
60+
compile 'com.google.firebase:firebase-auth:11.0.4'
6261

6362
testCompile 'junit:junit:4.12'
6463
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

app/src/main/java/io/github/javiewer/Javiewer.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import java.io.File;
1717
import java.io.IOException;
18-
import java.net.URI;
19-
import java.net.URISyntaxException;
2018
import java.util.ArrayList;
2119
import java.util.HashMap;
2220
import java.util.List;
@@ -51,11 +49,7 @@ public class JAViewer extends Application {
5149

5250
public static Configurations CONFIGURATIONS;
5351

54-
public static final List<DataSource> DATA_SOURCES = new ArrayList<DataSource>() {{
55-
add(DataSource.AVMO);
56-
add(DataSource.AVSO);
57-
add(DataSource.AVXO);
58-
}};
52+
public static final List<DataSource> DATA_SOURCES = new ArrayList<>();
5953

6054
public static final Map<Integer, Class<? extends Fragment>> FRAGMENTS = new HashMap<Integer, Class<? extends Fragment>>() {{
6155
put(R.id.nav_home, HomeFragment.class);
@@ -97,9 +91,9 @@ public static HttpUrl replaceUrl(HttpUrl url) {
9791
return url;
9892
}
9993

100-
private static Map<String, String> hostReplacements = new HashMap<>();
94+
public static Map<String, String> hostReplacements = new HashMap<>();
10195

102-
static {
96+
/*static {
10397
String host;
10498
try {
10599
host = new URI(DataSource.AVMO.getLink()).getHost();
@@ -115,7 +109,7 @@ public static HttpUrl replaceUrl(HttpUrl url) {
115109
} catch (URISyntaxException e) {
116110
throw new RuntimeException(e);
117111
}
118-
}
112+
}*/
119113

120114

121115
public static final OkHttpClient HTTP_CLIENT = new OkHttpClient.Builder().addInterceptor(new Interceptor() {

app/src/main/java/io/github/javiewer/Properties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.github.javiewer;
22

3+
import java.util.List;
4+
5+
import io.github.javiewer.adapter.item.DataSource;
6+
37
/**
48
* Project: JAViewer
59
*/
@@ -10,6 +14,10 @@ public class Properties {
1014
private int latest_version_code;
1115

1216
private String changelog;
17+
private List<DataSource> data_sources;
18+
19+
public Properties() {
20+
}
1321

1422
public String getLatestVersion() {
1523
return latest_version;
@@ -19,6 +27,10 @@ public int getLatestVersionCode() {
1927
return latest_version_code;
2028
}
2129

30+
public List<DataSource> getDataSources() {
31+
return data_sources;
32+
}
33+
2234
public String getChangelog() {
2335
return changelog;
2436
}

app/src/main/java/io/github/javiewer/activity/GalleryActivity.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
3333
import com.bumptech.glide.request.animation.GlideAnimation;
3434
import com.bumptech.glide.request.target.SimpleTarget;
35+
import com.github.chrisbanes.photoview.OnPhotoTapListener;
36+
import com.github.chrisbanes.photoview.PhotoView;
37+
import com.github.chrisbanes.photoview.PhotoViewAttacher;
3538

3639
import java.io.BufferedOutputStream;
3740
import java.io.File;
@@ -151,7 +154,7 @@ public boolean onTouch(View v, MotionEvent event) {
151154

152155
Bundle bundle = this.getIntent().getExtras();
153156

154-
mPager.setAdapter(new ImageAdapter(this, imageUrls = bundle.getStringArray("urls")));
157+
mPager.setAdapter(new ImageAdapter(this, imageUrls = bundle.getStringArray("urls"), this));
155158
mPager.setCurrentItem(bundle.getInt("position"));
156159
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
157160
@Override
@@ -178,7 +181,7 @@ private void updateIndicator() {
178181
//mTextIndicator.setText((mPager.getCurrentItem() + 1) + " / " + (imageUrls.length));
179182
}
180183

181-
private void toggle() {
184+
public void toggle() {
182185
if (mVisible) {
183186
hide();
184187
} else {
@@ -273,13 +276,14 @@ public boolean onSupportNavigateUp() {
273276

274277
private static class ImageAdapter extends PagerAdapter {
275278

279+
private GalleryActivity mActivity;
276280
private final String[] imageUrls;
277281
private LayoutInflater inflater;
278282
//private DisplayImageOptions options;
279283

280-
ImageAdapter(Context context, String[] imageUrls) {
284+
ImageAdapter(Context context, String[] imageUrls, GalleryActivity mActivity) {
281285
inflater = LayoutInflater.from(context);
282-
286+
this.mActivity = mActivity;
283287
this.imageUrls = imageUrls;
284288
}
285289

@@ -296,10 +300,24 @@ public int getCount() {
296300
@Override
297301
public Object instantiateItem(ViewGroup view, int position) {
298302
View imageLayout = inflater.inflate(R.layout.content_gallery, view, false);
299-
final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
300-
final ProgressBar progressBar = (ProgressBar) imageLayout.findViewById(R.id.progress_bar);
301-
final TextView textView = (TextView) imageLayout.findViewById(R.id.gallery_text_error);
302-
303+
final PhotoView imageView = imageLayout.findViewById(R.id.image);
304+
final ProgressBar progressBar = imageLayout.findViewById(R.id.progress_bar);
305+
final TextView textView = imageLayout.findViewById(R.id.gallery_text_error);
306+
307+
PhotoViewAttacher attacher = new PhotoViewAttacher(imageView);
308+
/*attacher.setOnViewTapListener(new OnViewTapListener() {
309+
@Override
310+
public void onViewTap(View view, float x, float y) {
311+
mActivity.toggle();
312+
}
313+
});
314+
*/
315+
attacher.setOnPhotoTapListener(new OnPhotoTapListener() {
316+
@Override
317+
public void onPhotoTap(ImageView view, float x, float y) {
318+
mActivity.toggle();
319+
}
320+
});
303321
Glide.with(imageView.getContext().getApplicationContext())
304322
.load(imageUrls[position])
305323
.into(new SimpleTarget<GlideDrawable>() {

app/src/main/java/io/github/javiewer/activity/MainActivity.java

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import android.net.Uri;
77
import android.os.Build;
88
import android.os.Bundle;
9-
import android.os.Handler;
10-
import android.os.Looper;
119
import android.support.annotation.NonNull;
1210
import android.support.design.widget.AppBarLayout;
1311
import android.support.design.widget.NavigationView;
@@ -27,8 +25,9 @@
2725
import android.widget.ArrayAdapter;
2826
import android.widget.Spinner;
2927

30-
import java.io.IOException;
3128
import java.io.UnsupportedEncodingException;
29+
import java.net.URI;
30+
import java.net.URISyntaxException;
3231
import java.net.URLEncoder;
3332

3433
import butterknife.BindView;
@@ -41,10 +40,6 @@
4140
import io.github.javiewer.fragment.ExtendedAppBarFragment;
4241
import io.github.javiewer.network.BasicService;
4342
import io.github.javiewer.view.SimpleSearchView;
44-
import okhttp3.Call;
45-
import okhttp3.Callback;
46-
import okhttp3.Request;
47-
import okhttp3.Response;
4843

4944
public class MainActivity extends AppCompatActivity
5045
implements NavigationView.OnNavigationItemSelectedListener {
@@ -143,31 +138,21 @@ public void onNothingSelected(AdapterView<?> parent) {
143138
}
144139
});
145140

146-
Request request = new Request.Builder()
147-
.url("https://raw.githubusercontent.com/SplashCodes/JAViewer/master/properties.json")
148-
.build();
149-
JAViewer.HTTP_CLIENT.newCall(request).enqueue(new Callback() {
150-
@Override
151-
public void onFailure(Call call, IOException e) {
152-
}
153-
154-
@Override
155-
public void onResponse(Call call, Response response) throws IOException {
156-
final Properties properties = JAViewer.parseJson(Properties.class, response.body().string());
157-
if (properties != null) {
158-
new Handler(Looper.getMainLooper()).post(new Runnable() {
159-
@Override
160-
public void run() {
161-
handleProperties(properties);
162-
}
163-
});
164-
}
165-
}
166-
});
167141

168142
}
169143

170-
public void handleProperties(Properties properties) {
144+
public void handleProperties(Properties properties) throws URISyntaxException {
145+
JAViewer.DATA_SOURCES.clear();
146+
JAViewer.DATA_SOURCES.addAll(properties.getDataSources());
147+
148+
JAViewer.hostReplacements.clear();
149+
for (DataSource source : JAViewer.DATA_SOURCES) {
150+
String host = new URI(source.getLink()).getHost();
151+
for (String h : source.legacies) {
152+
JAViewer.hostReplacements.put(h, host);
153+
}
154+
}
155+
171156
int currentVersion;
172157
try {
173158
currentVersion = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
@@ -343,10 +328,13 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
343328
}
344329

345330
public void restart() {
346-
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
331+
/*Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
347332
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
348333
startActivity(i);
334+
finish();*/
335+
Intent intent = getIntent();
349336
finish();
337+
startActivity(intent);
350338
}
351339

352340
}

app/src/main/java/io/github/javiewer/activity/MovieActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
112112
MovieDetail detail;
113113
try {
114114
detail = AVMOProvider.parseMoviesDetail(response.body().string());
115+
detail.headers.add(0, MovieDetail.Header.create("影片名", movie.getTitle(), null));
115116
displayInfo(detail);
116117

117118
Glide.with(mToolbarLayoutBackground.getContext().getApplicationContext())

app/src/main/java/io/github/javiewer/activity/StartActivity.java

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import android.content.DialogInterface;
55
import android.content.Intent;
66
import android.content.pm.PackageManager;
7+
import android.net.Uri;
78
import android.os.Build;
89
import android.os.Bundle;
10+
import android.os.Handler;
11+
import android.os.Looper;
912
import android.support.v7.app.AlertDialog;
1013
import android.support.v7.app.AppCompatActivity;
1114

@@ -21,7 +24,12 @@
2124

2225
import io.github.javiewer.Configurations;
2326
import io.github.javiewer.JAViewer;
27+
import io.github.javiewer.Properties;
2428
import io.github.javiewer.R;
29+
import okhttp3.Call;
30+
import okhttp3.Callback;
31+
import okhttp3.Request;
32+
import okhttp3.Response;
2533

2634
public class StartActivity extends AppCompatActivity {
2735

@@ -31,7 +39,68 @@ protected void onCreate(Bundle savedInstanceState) {
3139
super.onCreate(savedInstanceState);
3240
setContentView(R.layout.activity_start);
3341

34-
checkPermissions();
42+
checkPermissions(); //检查权限,创建配置
43+
}
44+
45+
public void readProperties() {
46+
Request request = new Request.Builder()
47+
.url("https://raw.githubusercontent.com/SplashCodes/JAViewer/master/properties.json")
48+
.build();
49+
JAViewer.HTTP_CLIENT.newCall(request).enqueue(new Callback() {
50+
@Override
51+
public void onFailure(Call call, IOException e) {
52+
}
53+
54+
@Override
55+
public void onResponse(Call call, Response response) throws IOException {
56+
final Properties properties = JAViewer.parseJson(Properties.class, response.body().string());
57+
if (properties != null) {
58+
new Handler(Looper.getMainLooper()).post(new Runnable() {
59+
@Override
60+
public void run() {
61+
handleProperties(properties);
62+
}
63+
});
64+
}
65+
}
66+
});
67+
}
68+
69+
public void handleProperties(Properties properties) {
70+
JAViewer.DATA_SOURCES.clear();
71+
JAViewer.DATA_SOURCES.addAll(properties.getDataSources());
72+
73+
74+
int currentVersion;
75+
try {
76+
currentVersion = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
77+
} catch (PackageManager.NameNotFoundException e) {
78+
throw new RuntimeException("Hacked???");
79+
}
80+
81+
if (properties.getLatestVersionCode() > 0 && currentVersion < properties.getLatestVersionCode()) {
82+
83+
String message = "新版本:" + properties.getLatestVersion();
84+
if (properties.getChangelog() != null) {
85+
message += "\n\n更新日志:\n\n" + properties.getChangelog() + "\n";
86+
}
87+
88+
AlertDialog dialog = new AlertDialog.Builder(this)
89+
.setTitle("发现更新")
90+
.setMessage(message)
91+
.setNegativeButton("忽略更新", null)
92+
.setPositiveButton("更新", new DialogInterface.OnClickListener() {
93+
@Override
94+
public void onClick(DialogInterface dialog, int which) {
95+
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/SplashCodes/JAViewer/releases")));
96+
}
97+
})
98+
.create();
99+
dialog.show();
100+
}
101+
102+
startActivity(new Intent(StartActivity.this, MainActivity.class));
103+
finish();
35104
}
36105

37106
private void checkPermissions() {
@@ -84,8 +153,7 @@ public void onPermissionRationaleShouldBeShown(PermissionRequest permission, Per
84153

85154
JAViewer.CONFIGURATIONS = Configurations.load(config);
86155

87-
startActivity(new Intent(StartActivity.this, MainActivity.class));
88-
finish();
156+
readProperties();
89157
}
90158

91159
}

app/src/main/java/io/github/javiewer/adapter/item/DataSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.javiewer.adapter.item;
22

3+
import java.util.List;
4+
35
/**
46
* Project: JAViewer
57
*/
@@ -12,6 +14,7 @@ public class DataSource extends Linkable {
1214

1315

1416
public String name;
17+
public List<String> legacies;
1518

1619
public DataSource(String name, String baseUrl) {
1720
this.name = name;

0 commit comments

Comments
 (0)