First post the code address: github.com/Pr-Jiang/Ne…

Recently, there are not many information meetings, so I should really calm down and do something practical.

I spent two and a half days alone in my dormitory to complete this relatively complete project. Also refer to the open source project on Github

Retrofit+RxJava for network requests, especially in the thread switch, is really powerful ~~

The flash screen page is not supported because the GIF image is too large, so if you are interested, you can go to Github for a look

I also hope that you can star and help me find my ideal offer in the school recruitment ~

The fish thanked him here

Here’s the main screen:

MaterialDesign style is adopted, EasyRecyclerView is used, and the item is wrapped by CardView

Data comes from sky line data

private void easyGetDatas() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(NewsFragment.BASE_URL) AddConverterFactory (GsonConverterFactory. The create (), add Gson converter / * * / AddCallAdapterFactory (RxJavaCallAdapterFactory. The create (), add RxJava adapter / * * /. The build (); NewsService newsService = retrofit.create(NewsService.class); newsService.getNewsDatas(NewsFragment.APIKEY, "10", / / map(new Func1>() {@override public List call(News News) { return news.getNewslist(); }}). ObserveOn (AndroidSchedulers mainThread ()) threads behind / * will switch to the main thread * /. The subscribe (new Subscriber > () {@ Override public void onCompleted() { easyRecyclerView.setRefreshing(false); } @Override public void onError(Throwable e) { Snackbar.make(easyRecyclerView, R.string.network_error, Snackbar.LENGTH_LONG).show(); } @Override public void onNext(List newslistBeen) { adapter.addAll(newslistBeen); }}); page++; }Copy the code

News details:




Waterfall flow pictures:

EasyRecyclerView is also used

Data from gank.io




Big PIC:

Load images with Picasso

Picasso loads full size pictures with higher quality than Glide

Glide Glide has the advantage of loading GIF images and loading images to the ImageView size




Save images using RxJava~

The code is as follows:

private void savePicture(final Context context, final String id) { Observable.create(new Observable.OnSubscribe() { @Override public void call(Subscriber subscriber) { Bitmap bitmap = null; Try {/* Picasso = Picasso.with(context).load(bitmapUrl).get(); } catch (IOException e) { subscriber.onError(e); } if (bitmap == null) {subscriber. OnError (new Exception(" unable to download image ")); } subscriber.onNext(bitmap); subscriber.onCompleted(); } }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(Bitmap bitmap)  { File appDir = new File(Environment.getExternalStorageDirectory(), "NewsAPP"); String pictureName = id + ".jpg"; File file = new File(appDir, pictureName); try { FileOutputStream outputStream = new FileOutputStream(file); /* Assert,true continues,false java.lang.assertionError */ assert (bitmap! = null); / compressed images * * * * @ param quality compression ratio of 100 said without compression press * / bitmap.com (bitmap.com pressFormat. JPEG, 100, outputStream); outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } /* Notify gallery update */ Uri Uri = uri.fromfile (file); context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri)); Toast.maketext (context, "image saved to" + Appdir.getabsolutePath () + "folder ", toast.length_short).show(); toast.maketext (context," image saved to "+ Appdir.getabsolutePath () +" folder ", toast.length_short). }}); }Copy the code

Right! Remember to add network access and storage write permissions!