From 0c99afe097ff59d00e43c04dee7cd825fae34008 Mon Sep 17 00:00:00 2001 From: SplashCodes Date: Sat, 24 Sep 2016 16:01:17 +0800 Subject: [PATCH] =?UTF-8?q?JAViewer=201.1=20=E5=AE=8C=E6=95=B4=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 +- .../java/io/github/javiewer/Javiewer.java | 25 +++- .../javiewer/activity/MainActivity.java | 17 ++- .../javiewer/activity/MovieActivity.java | 97 ++++++++++---- .../javiewer/adapter/ActressAdapter.java | 4 +- .../adapter/ActressPaletteAdapter.java | 121 ++++++++++++++++++ .../github/javiewer/adapter/GenreAdapter.java | 10 +- .../github/javiewer/adapter/MovieAdapter.java | 4 +- .../javiewer/adapter/MovieHeaderAdapter.java | 100 +++++++++++++++ .../javiewer/adapter/ScreenshotAdapter.java | 4 +- .../github/javiewer/adapter/item/Genre.java | 15 ++- .../javiewer/adapter/item/Linkable.java | 2 +- .../javiewer/adapter/item/MovieDetail.java | 24 +++- .../java/io/github/javiewer/network/AVMO.java | 4 +- .../java/io/github/javiewer/network/BTSO.java | 4 +- .../github/javiewer/network/TorrentKitty.java | 4 +- .../network/provider/AVMOProvider.java | 98 +++++++++++--- .../javiewer/view/ActressImageView.java | 36 ++++++ .../javiewer/view/ActressScaleImageView.java | 2 +- .../github/javiewer/view/ScaleImageView.java | 4 - ...t_actresses.xml => ic_movie_actresses.xml} | 0 app/src/main/res/drawable/ic_movie_genre.xml | 9 ++ ...c_default_photo.xml => ic_movie_photo.xml} | 0 app/src/main/res/layout/card_actress.xml | 2 +- .../main/res/layout/card_actress_palette.xml | 38 ++++++ app/src/main/res/layout/card_download.xml | 9 +- app/src/main/res/layout/card_genre.xml | 5 +- app/src/main/res/layout/card_genre_movie.xml | 29 +++++ app/src/main/res/layout/content_movie.xml | 16 ++- .../res/layout/content_movie_actresses.xml | 45 +++++++ .../main/res/layout/content_movie_genre.xml | 46 +++++++ .../main/res/layout/content_movie_headers.xml | 45 +++++++ .../main/res/layout/content_movie_info.xml | 103 --------------- .../res/layout/content_movie_screenshots.xml | 6 +- app/src/main/res/layout/layout_header.xml | 33 +++++ properties.json | 4 +- 36 files changed, 776 insertions(+), 201 deletions(-) create mode 100644 app/src/main/java/io/github/javiewer/adapter/ActressPaletteAdapter.java create mode 100644 app/src/main/java/io/github/javiewer/adapter/MovieHeaderAdapter.java create mode 100644 app/src/main/java/io/github/javiewer/view/ActressImageView.java rename app/src/main/res/drawable/{ic_default_actresses.xml => ic_movie_actresses.xml} (100%) create mode 100644 app/src/main/res/drawable/ic_movie_genre.xml rename app/src/main/res/drawable/{ic_default_photo.xml => ic_movie_photo.xml} (100%) create mode 100644 app/src/main/res/layout/card_actress_palette.xml create mode 100644 app/src/main/res/layout/card_genre_movie.xml create mode 100644 app/src/main/res/layout/content_movie_actresses.xml create mode 100644 app/src/main/res/layout/content_movie_genre.xml create mode 100644 app/src/main/res/layout/content_movie_headers.xml delete mode 100644 app/src/main/res/layout/content_movie_info.xml create mode 100644 app/src/main/res/layout/layout_header.xml diff --git a/app/build.gradle b/app/build.gradle index 8e60b62..92ace29 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 15 targetSdkVersion 24 versionCode 1 - versionName "1.0" + versionName "1.1" } buildTypes { release { @@ -23,13 +23,15 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'jp.wasabeef:recyclerview-animators:2.2.3' - compile 'com.android.support:appcompat-v7:24.1.1' - compile 'com.android.support:design:24.1.1' + compile 'com.android.support:appcompat-v7:24.2.1' + compile "com.wefika:flowlayout:0.4.1" + compile 'com.android.support:design:24.2.1' compile 'com.jakewharton:butterknife:7.0.1' + compile 'com.android.support:palette-v7:24.2.1' compile 'com.squareup.retrofit2:retrofit:2.0.2' - compile 'com.android.support:support-v4:24.1.1' + compile 'com.android.support:support-v4:24.2.1' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' compile 'org.jsoup:jsoup:1.9.2' compile 'com.google.code.gson:gson:2.7' - compile 'com.android.support:cardview-v7:24.1.1' + compile 'com.android.support:cardview-v7:24.2.1' } diff --git a/app/src/main/java/io/github/javiewer/Javiewer.java b/app/src/main/java/io/github/javiewer/Javiewer.java index c6c11e4..67b679b 100644 --- a/app/src/main/java/io/github/javiewer/Javiewer.java +++ b/app/src/main/java/io/github/javiewer/Javiewer.java @@ -9,9 +9,15 @@ import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import io.github.javiewer.network.BTSO; import io.github.javiewer.network.TorrentKitty; +import okhttp3.Cookie; +import okhttp3.CookieJar; +import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -22,7 +28,7 @@ * Created by MagicDroidX on 2016/9/23. */ -public class Javiewer { +public class JAViewer { public static final String VERSION = "1.0.1"; public static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36"; @@ -38,7 +44,22 @@ public Response intercept(Interceptor.Chain chain) throws IOException { return chain.proceed(request); } - }).build(); + }) + .cookieJar(new CookieJar() { + private final HashMap> cookieStore = new HashMap<>(); + + @Override + public void saveFromResponse(HttpUrl url, List cookies) { + cookieStore.put(url, cookies); + } + + @Override + public List loadForRequest(HttpUrl url) { + List cookies = cookieStore.get(url); + return cookies != null ? cookies : new ArrayList(); + } + }) + .build(); public static final Retrofit RETROFIT_BTSO = new Retrofit.Builder() .baseUrl(BTSO.BASE_URL) diff --git a/app/src/main/java/io/github/javiewer/activity/MainActivity.java b/app/src/main/java/io/github/javiewer/activity/MainActivity.java index 0c1df18..cabc000 100644 --- a/app/src/main/java/io/github/javiewer/activity/MainActivity.java +++ b/app/src/main/java/io/github/javiewer/activity/MainActivity.java @@ -38,7 +38,7 @@ import butterknife.Bind; import butterknife.ButterKnife; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import io.github.javiewer.Properties; import io.github.javiewer.R; import io.github.javiewer.fragment.ActressesFragment; @@ -90,7 +90,7 @@ protected void onCreate(Bundle savedInstanceState) { AlertDialog dialog = new AlertDialog.Builder(this) .setCancelable(false) .setTitle("提示") - .setMessage("你好!\n欢迎使用Javiewer!\n即将请求储存空间权限,用于图片缓存功能,减少重复流量消耗") + .setMessage("你好!\n欢迎使用JAViewer!\n即将请求储存空间权限,用于图片缓存功能,减少重复流量消耗") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -108,14 +108,14 @@ public void onClick(DialogInterface dialog, int which) { Request request = new Request.Builder() .url("https://raw.githubusercontent.com/SplashCodes/JAViewer/master/properties.json") .build(); - Javiewer.HTTP_CLIENT.newCall(request).enqueue(new Callback() { + JAViewer.HTTP_CLIENT.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { - final Properties properties = Javiewer.parseJson(Properties.class, response.body().string()); + final Properties properties = JAViewer.parseJson(Properties.class, response.body().string()); if (properties != null) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override @@ -129,7 +129,14 @@ public void run() { } public void handleProperties(Properties properties) { - if (properties.getLatestVersion() != null && !Javiewer.VERSION.equals(properties.getLatestVersion())) { + String currentVersion; + try { + currentVersion = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; + } catch (PackageManager.NameNotFoundException e) { + throw new RuntimeException("Hacked???"); + } + + if (properties.getLatestVersion() != null && !currentVersion.trim().equals(properties.getLatestVersion().trim())) { String message = "新版本:" + properties.getLatestVersion(); if (properties.getChangelog() != null) { diff --git a/app/src/main/java/io/github/javiewer/activity/MovieActivity.java b/app/src/main/java/io/github/javiewer/activity/MovieActivity.java index 1145eda..64ec38b 100644 --- a/app/src/main/java/io/github/javiewer/activity/MovieActivity.java +++ b/app/src/main/java/io/github/javiewer/activity/MovieActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import android.support.v7.widget.Toolbar; @@ -14,17 +15,18 @@ import android.widget.TextView; import com.nostra13.universalimageloader.core.ImageLoader; +import com.wefika.flowlayout.FlowLayout; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import butterknife.Bind; import butterknife.ButterKnife; import io.github.javiewer.R; +import io.github.javiewer.adapter.ActressPaletteAdapter; +import io.github.javiewer.adapter.MovieHeaderAdapter; import io.github.javiewer.adapter.ScreenshotAdapter; +import io.github.javiewer.adapter.item.Genre; import io.github.javiewer.adapter.item.MovieDetail; -import io.github.javiewer.adapter.item.Screenshot; import io.github.javiewer.network.AVMO; import io.github.javiewer.network.provider.AVMOProvider; import io.github.javiewer.view.ViewUtil; @@ -49,10 +51,10 @@ public class MovieActivity extends AppCompatActivity { @Bind(R.id.fab) FloatingActionButton mFab; - String code; - + @Bind(R.id.genre_flow_layout) + FlowLayout mFlowLayout; - List screenshots = new ArrayList<>(); + String code; @Override protected void onCreate(Bundle savedInstanceState) { @@ -96,9 +98,6 @@ public void onResponse(Call call, Response response) ImageLoader.getInstance().displayImage(detail.coverUrl, mToolbarLayoutBackgroud); - screenshots.clear(); - screenshots.addAll(detail.screenshots); - displayInfo(detail); } catch (IOException e) { onFailure(call, e); @@ -124,30 +123,84 @@ private void displayInfo(MovieDetail detail) { //Info { - TextView mCodeText = (TextView) findViewById(R.id.info_text_code); - TextView mDateText = (TextView) findViewById(R.id.info_text_date); - TextView mDurationText = (TextView) findViewById(R.id.info_text_duration); - mCodeText.setText(detail.code); - mDateText.setText(detail.date); - mDurationText.setText(detail.duration); + RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.headers_recycler_view); + TextView mText = (TextView) findViewById(R.id.header_empty_text); + ImageView mIcon = (ImageView) findViewById(R.id.movie_icon_header); + + if (detail.headers.isEmpty()) { + mRecyclerView.setVisibility(View.GONE); + mText.setVisibility(View.VISIBLE); + ViewUtil.alignIconToView(mIcon, mText); + } else { + mRecyclerView.setAdapter(new MovieHeaderAdapter(detail.headers, this, mIcon)); + mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); + mRecyclerView.setNestedScrollingEnabled(false); + } } //Screenshots { RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.screenshots_recycler_view); - TextView mText = (TextView) findViewById(R.id.screenshots_text); - ImageView mIcon = (ImageView) findViewById(R.id.movie_icon_photo); + TextView mText = (TextView) findViewById(R.id.screenshots_empty_text); + ImageView mIcon = (ImageView) findViewById(R.id.movie_icon_screenshots); + + if (detail.screenshots.isEmpty()) { + mRecyclerView.setVisibility(View.GONE); + mText.setVisibility(View.VISIBLE); + ViewUtil.alignIconToView(mIcon, mText); + } else { + mRecyclerView.setAdapter(new ScreenshotAdapter(detail.screenshots, this, mIcon)); + mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL)); + mRecyclerView.setNestedScrollingEnabled(false); + } + } - mRecyclerView.setAdapter(new ScreenshotAdapter(screenshots, this, mIcon)); - mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL)); - mRecyclerView.setNestedScrollingEnabled(false); + //Actress + { + RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.actresses_recycler_view); + TextView mText = (TextView) findViewById(R.id.actresses_empty_text); + ImageView mIcon = (ImageView) findViewById(R.id.movie_icon_actresses); - if (screenshots.isEmpty()) { + if (detail.actresses.isEmpty()) { mRecyclerView.setVisibility(View.GONE); mText.setVisibility(View.VISIBLE); + ViewUtil.alignIconToView(mIcon, mText); + } else { + mRecyclerView.setAdapter(new ActressPaletteAdapter(detail.actresses, this, mIcon)); + mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); + mRecyclerView.setNestedScrollingEnabled(false); } + } - ViewUtil.alignIconToView(mIcon, mText); + { + boolean first = true; + for (final Genre genre : detail.genres) { + View view = getLayoutInflater().inflate(R.layout.card_genre_movie, mFlowLayout, false); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (genre.getLink() != null) { + Intent intent = new Intent(MovieActivity.this, MovieListActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("title", genre.getName()); + bundle.putString("query", genre.getLink()); + + intent.putExtras(bundle); + startActivity(intent); + } + } + }); + TextView textView = (TextView) view.findViewById(R.id.chip_genre_name); + textView.setText(genre.getName()); + + mFlowLayout.addView(view); + + if (first) { + ImageView mIcon = (ImageView) findViewById(R.id.movie_icon_genre); + ViewUtil.alignIconToView(mIcon, view); + first = false; + } + } } } diff --git a/app/src/main/java/io/github/javiewer/adapter/ActressAdapter.java b/app/src/main/java/io/github/javiewer/adapter/ActressAdapter.java index d223068..f876d0b 100644 --- a/app/src/main/java/io/github/javiewer/adapter/ActressAdapter.java +++ b/app/src/main/java/io/github/javiewer/adapter/ActressAdapter.java @@ -17,7 +17,7 @@ import butterknife.Bind; import butterknife.ButterKnife; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import io.github.javiewer.R; import io.github.javiewer.activity.MovieListActivity; import io.github.javiewer.adapter.item.Actress; @@ -67,7 +67,7 @@ public void onClick(View v) { }); - ImageLoader.getInstance().displayImage(actress.getImageUrl(), holder.mImage, Javiewer.DISPLAY_IMAGE_OPTIONS); + ImageLoader.getInstance().displayImage(actress.getImageUrl(), holder.mImage, JAViewer.DISPLAY_IMAGE_OPTIONS); } @Override diff --git a/app/src/main/java/io/github/javiewer/adapter/ActressPaletteAdapter.java b/app/src/main/java/io/github/javiewer/adapter/ActressPaletteAdapter.java new file mode 100644 index 0000000..3469cb5 --- /dev/null +++ b/app/src/main/java/io/github/javiewer/adapter/ActressPaletteAdapter.java @@ -0,0 +1,121 @@ +package io.github.javiewer.adapter; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.os.Bundle; +import android.support.v7.graphics.Palette; +import android.support.v7.widget.CardView; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.nostra13.universalimageloader.core.ImageLoader; +import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; + +import java.util.List; + +import butterknife.Bind; +import butterknife.ButterKnife; +import io.github.javiewer.JAViewer; +import io.github.javiewer.R; +import io.github.javiewer.activity.MovieListActivity; +import io.github.javiewer.adapter.item.Actress; +import io.github.javiewer.view.ViewUtil; + +/** + * Created by MagicDroidX on 2016/9/23. + */ + +public class ActressPaletteAdapter extends RecyclerView.Adapter { + + private List actresses; + + private Activity mParentActivity; + + private ImageView mIcon; + + public ActressPaletteAdapter(List actresses, Activity mParentActivity, ImageView mIcon) { + this.actresses = actresses; + this.mParentActivity = mParentActivity; + this.mIcon = mIcon; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_actress_palette, parent, false); + + return new ViewHolder(v); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + final Actress actress = actresses.get(position); + + holder.mCard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (actress.getLink() != null) { + Intent intent = new Intent(mParentActivity, MovieListActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("title", actress.getName() + " 的作品"); + bundle.putString("query", actress.getLink()); + + intent.putExtras(bundle); + + mParentActivity.startActivity(intent); + } + } + }); + + ImageLoader.getInstance().displayImage(actress.getImageUrl(), holder.mImage, JAViewer.DISPLAY_IMAGE_OPTIONS, new SimpleImageLoadingListener() { + @Override + public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { + super.onLoadingComplete(imageUri, view, loadedImage); + + Palette.from(loadedImage).generate(new Palette.PaletteAsyncListener() { + @Override + public void onGenerated(Palette palette) { + Palette.Swatch swatch = palette.getLightVibrantSwatch(); + if (swatch == null) { + return; + } + holder.mCard.setCardBackgroundColor(swatch.getRgb()); + holder.mName.setTextColor(swatch.getBodyTextColor()); + } + }); + } + }); + + holder.mName.setText(actress.getName()); + + if (position == 0) { + ViewUtil.alignIconToView(mIcon, holder.mImage); + } + } + + @Override + public int getItemCount() { + return actresses == null ? 0 : actresses.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + @Bind(R.id.actress_palette_img) + public ImageView mImage; + + @Bind(R.id.actress_palette_name) + public TextView mName; + + @Bind(R.id.card_actress_palette) + public CardView mCard; + + public ViewHolder(View view) { + super(view); + ButterKnife.bind(this, view); + } + } +} diff --git a/app/src/main/java/io/github/javiewer/adapter/GenreAdapter.java b/app/src/main/java/io/github/javiewer/adapter/GenreAdapter.java index 8cdcb04..d3028ce 100644 --- a/app/src/main/java/io/github/javiewer/adapter/GenreAdapter.java +++ b/app/src/main/java/io/github/javiewer/adapter/GenreAdapter.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -44,13 +45,13 @@ public void onBindViewHolder(final ViewHolder holder, int position) { final Genre genre = genres.get(position); holder.parse(genre); - holder.mTextName.setOnClickListener(new View.OnClickListener() { + holder.mCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (genre.getLink() != null) { Intent intent = new Intent(mParentActivity, MovieListActivity.class); Bundle bundle = new Bundle(); - bundle.putString("title", genre.getTitle()); + bundle.putString("title", genre.getName()); bundle.putString("query", genre.getLink()); intent.putExtras(bundle); @@ -71,8 +72,11 @@ public static class ViewHolder extends RecyclerView.ViewHolder { @Bind(R.id.genre_name) public TextView mTextName; + @Bind(R.id.card_genre) + public CardView mCard; + public void parse(Genre genre) { - mTextName.setText(genre.getTitle()); + mTextName.setText(genre.getName()); } public ViewHolder(View view) { diff --git a/app/src/main/java/io/github/javiewer/adapter/MovieAdapter.java b/app/src/main/java/io/github/javiewer/adapter/MovieAdapter.java index 73c75a2..8444b77 100644 --- a/app/src/main/java/io/github/javiewer/adapter/MovieAdapter.java +++ b/app/src/main/java/io/github/javiewer/adapter/MovieAdapter.java @@ -17,7 +17,7 @@ import butterknife.Bind; import butterknife.ButterKnife; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import io.github.javiewer.R; import io.github.javiewer.activity.MovieActivity; import io.github.javiewer.adapter.item.Movie; @@ -63,7 +63,7 @@ public void onClick(View v) { } }); - ImageLoader.getInstance().displayImage(movie.getCoverUrl(), holder.mImageCover, Javiewer.DISPLAY_IMAGE_OPTIONS); + ImageLoader.getInstance().displayImage(movie.getCoverUrl(), holder.mImageCover, JAViewer.DISPLAY_IMAGE_OPTIONS); holder.mImageHot.setVisibility(movie.isHot() ? View.VISIBLE : View.INVISIBLE); } diff --git a/app/src/main/java/io/github/javiewer/adapter/MovieHeaderAdapter.java b/app/src/main/java/io/github/javiewer/adapter/MovieHeaderAdapter.java new file mode 100644 index 0000000..3571de4 --- /dev/null +++ b/app/src/main/java/io/github/javiewer/adapter/MovieHeaderAdapter.java @@ -0,0 +1,100 @@ +package io.github.javiewer.adapter; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Paint; +import android.os.Bundle; +import android.support.v4.content.res.ResourcesCompat; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +import butterknife.Bind; +import butterknife.ButterKnife; +import io.github.javiewer.R; +import io.github.javiewer.activity.MovieListActivity; +import io.github.javiewer.adapter.item.MovieDetail; +import io.github.javiewer.view.ViewUtil; + +/** + * Created by MagicDroidX on 2016/9/23. + */ + +public class MovieHeaderAdapter extends RecyclerView.Adapter { + + private List headers; + + private Activity mParentActivity; + + private ImageView mIcon; + + public boolean first = true; + + public MovieHeaderAdapter(List headers, Activity mParentActivity, ImageView mIcon) { + this.headers = headers; + this.mParentActivity = mParentActivity; + this.mIcon = mIcon; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_header, parent, false); + + return new ViewHolder(v); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + final MovieDetail.Header header = headers.get(position); + + if (header.name != null && header.value != null) { + holder.mHeaderName.setText(header.name); + holder.mHeaderValue.setText(header.value); + + if (header.getLink() != null) { + holder.mHeaderValue.setPaintFlags(holder.mHeaderValue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + holder.mHeaderValue.setTextColor(ResourcesCompat.getColor(this.mParentActivity.getResources(), R.color.colorAccent, null)); + holder.mHeaderValue.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(mParentActivity, MovieListActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("title", header.getName() + " " + header.getValue()); + bundle.putString("query", header.getLink()); + intent.putExtras(bundle); + mParentActivity.startActivity(intent); + } + }); + } + + if (first) { + ViewUtil.alignIconToView(mIcon, holder.mHeaderName); + first = false; + } + } + } + + @Override + public int getItemCount() { + return headers == null ? 0 : headers.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + @Bind(R.id.header_name) + public TextView mHeaderName; + + @Bind(R.id.header_value) + public TextView mHeaderValue; + + public ViewHolder(View view) { + super(view); + ButterKnife.bind(this, view); + } + } +} diff --git a/app/src/main/java/io/github/javiewer/adapter/ScreenshotAdapter.java b/app/src/main/java/io/github/javiewer/adapter/ScreenshotAdapter.java index 096fb81..1ccd3c4 100644 --- a/app/src/main/java/io/github/javiewer/adapter/ScreenshotAdapter.java +++ b/app/src/main/java/io/github/javiewer/adapter/ScreenshotAdapter.java @@ -15,7 +15,7 @@ import butterknife.Bind; import butterknife.ButterKnife; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import io.github.javiewer.R; import io.github.javiewer.activity.GalleryActivity; import io.github.javiewer.adapter.item.Screenshot; @@ -50,7 +50,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public void onBindViewHolder(final ViewHolder holder, int position) { Screenshot screenshot = screenshots.get(position); - ImageLoader.getInstance().displayImage(screenshot.getThumbnailUrl(), holder.mImage, Javiewer.DISPLAY_IMAGE_OPTIONS); + ImageLoader.getInstance().displayImage(screenshot.getThumbnailUrl(), holder.mImage, JAViewer.DISPLAY_IMAGE_OPTIONS); holder.mImage.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/io/github/javiewer/adapter/item/Genre.java b/app/src/main/java/io/github/javiewer/adapter/item/Genre.java index 15e4dc5..de7270c 100644 --- a/app/src/main/java/io/github/javiewer/adapter/item/Genre.java +++ b/app/src/main/java/io/github/javiewer/adapter/item/Genre.java @@ -4,16 +4,21 @@ * Created by MagicDroidX on 2016/7/24. */ public class Genre extends Linkable { - protected String title; + public String name; - public static Genre create(String title, String link) { + public static Genre create(String name, String link) { Genre genre = new Genre(); - genre.title = title; + genre.name = name; genre.link = link; return genre; } - public String getTitle() { - return title; + public String getName() { + return name; + } + + @Override + public String toString() { + return name + ":" + link; } } diff --git a/app/src/main/java/io/github/javiewer/adapter/item/Linkable.java b/app/src/main/java/io/github/javiewer/adapter/item/Linkable.java index 153c5c9..67ef292 100644 --- a/app/src/main/java/io/github/javiewer/adapter/item/Linkable.java +++ b/app/src/main/java/io/github/javiewer/adapter/item/Linkable.java @@ -5,7 +5,7 @@ */ public class Linkable { - protected String link; + public String link; public String getLink() { return link; diff --git a/app/src/main/java/io/github/javiewer/adapter/item/MovieDetail.java b/app/src/main/java/io/github/javiewer/adapter/item/MovieDetail.java index afe6d24..b4ea024 100644 --- a/app/src/main/java/io/github/javiewer/adapter/item/MovieDetail.java +++ b/app/src/main/java/io/github/javiewer/adapter/item/MovieDetail.java @@ -14,9 +14,27 @@ public class MovieDetail { public final List screenshots = new ArrayList<>(); - public String code = "未知"; + public List
headers = new ArrayList<>(); - public String date = "未知"; + public List genres = new ArrayList<>(); - public String duration = "未知"; + public List actresses = new ArrayList<>(); + + public static class Header extends Linkable { + public String name; + public String value; + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return name + ":" + value + ":" + link; + } + } } diff --git a/app/src/main/java/io/github/javiewer/network/AVMO.java b/app/src/main/java/io/github/javiewer/network/AVMO.java index 835a3b1..78aeec5 100644 --- a/app/src/main/java/io/github/javiewer/network/AVMO.java +++ b/app/src/main/java/io/github/javiewer/network/AVMO.java @@ -1,6 +1,6 @@ package io.github.javiewer.network; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Retrofit; @@ -15,7 +15,7 @@ public interface AVMO { AVMO INSTANCE = new Retrofit.Builder() .baseUrl(AVMO.BASE_URL) - .client(Javiewer.HTTP_CLIENT) + .client(JAViewer.HTTP_CLIENT) .build() .create(AVMO.class); diff --git a/app/src/main/java/io/github/javiewer/network/BTSO.java b/app/src/main/java/io/github/javiewer/network/BTSO.java index f220128..cdbe2f5 100644 --- a/app/src/main/java/io/github/javiewer/network/BTSO.java +++ b/app/src/main/java/io/github/javiewer/network/BTSO.java @@ -1,6 +1,6 @@ package io.github.javiewer.network; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Retrofit; @@ -16,7 +16,7 @@ public interface BTSO { BTSO INSTANCE = new Retrofit.Builder() .baseUrl(BTSO.BASE_URL) - .client(Javiewer.HTTP_CLIENT) + .client(JAViewer.HTTP_CLIENT) .build() .create(BTSO.class); diff --git a/app/src/main/java/io/github/javiewer/network/TorrentKitty.java b/app/src/main/java/io/github/javiewer/network/TorrentKitty.java index 3a70184..ef85bb8 100644 --- a/app/src/main/java/io/github/javiewer/network/TorrentKitty.java +++ b/app/src/main/java/io/github/javiewer/network/TorrentKitty.java @@ -1,6 +1,6 @@ package io.github.javiewer.network; -import io.github.javiewer.Javiewer; +import io.github.javiewer.JAViewer; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Retrofit; @@ -16,7 +16,7 @@ public interface TorrentKitty { TorrentKitty INSTANCE = new Retrofit.Builder() .baseUrl(TorrentKitty.BASE_URL) - .client(Javiewer.HTTP_CLIENT) + .client(JAViewer.HTTP_CLIENT) .build() .create(TorrentKitty.class); diff --git a/app/src/main/java/io/github/javiewer/network/provider/AVMOProvider.java b/app/src/main/java/io/github/javiewer/network/provider/AVMOProvider.java index d6aa003..62e9116 100644 --- a/app/src/main/java/io/github/javiewer/network/provider/AVMOProvider.java +++ b/app/src/main/java/io/github/javiewer/network/provider/AVMOProvider.java @@ -81,36 +81,92 @@ public static List parseActresses(String html) { } public static MovieDetail parseMoviesDetail(String html) { - final String headerCode = "识别码"; - final String headerDate = "发行时间"; - final String headerDuration = "长度"; - Document document = Jsoup.parse(html); MovieDetail movie = new MovieDetail(); - movie.title = document.getElementsByTag("h3").first().text(); - movie.coverUrl = document.getElementsByClass("bigImage").first().attr("href"); - - for (Element element : document.getElementsByClass("sample-box")) { - movie.screenshots.add(Screenshot.create(element.getElementsByTag("img").first().attr("src"), element.attr("href"))); + //General Parsing + { + movie.title = document.getElementsByTag("h3").first().text(); + movie.coverUrl = document.getElementsByClass("bigImage").first().attr("href"); } - Element info = document.getElementsByClass("col-md-3").first(); - for (Element p : info.getElementsByTag("p")) { - - String[] s = p.text().split(":"); + //Parsing Screenshots + { + for (Element element : document.getElementsByClass("sample-box")) { + try { + movie.screenshots.add(Screenshot.create(element.getElementsByTag("img").first().attr("src"), element.attr("href"))); + } catch (Exception ignore) { + } + } + } - if (s.length > 1) { + //Parsing Headers + { + Element headerColumn = document.getElementsByClass("col-md-3").first(); + + List headerHeader = new ArrayList<>(); + List headerName = new ArrayList<>(); + + for (Element p : headerColumn.getElementsByTag("p")) { + String text = p.text(); + if (text.contains(":")) { + String[] s = text.split(":"); + MovieDetail.Header header = new MovieDetail.Header(); + header.name = s[0]; + + if (s.length > 1) { + header.value = s[1]; + movie.headers.add(header); + } else { + headerHeader.add(header); + } + } else { + Elements a = p.getElementsByTag("a"); + if (a.size() == 1) { + MovieDetail.Header header = new MovieDetail.Header(); + header.value = text; + header.link = a.first().attr("href"); + headerName.add(header); + } else if (a.size() > 1) { + for (Element genreE : p.getElementsByClass("genre")) { + Genre genre = new Genre(); + try { + genre.link = genreE.getElementsByTag("a").attr("href"); + } catch (Exception e) { + continue; + } + genre.name = genreE.text(); + movie.genres.add(genre); + } + } + } + } - String content = s[1].replace(" ", ""); + for (int i = 0; i < Math.min(headerHeader.size(), headerName.size()); i++) { + MovieDetail.Header header = new MovieDetail.Header(); + header.name = headerHeader.get(i).name; + header.value = headerName.get(i).value; + header.link = headerName.get(i).link; + movie.headers.add(header); + } + } - if (s[0].contains(headerCode)) { - movie.code = content; - } else if (s[0].contains(headerDate)) { - movie.date = content; - } else if (s[0].contains(headerDuration)) { - movie.duration = content; + //Parsing Actresses + { + Element actressWaterfall = document.getElementById("avatar-waterfall"); + if (actressWaterfall != null) { + for (Element box : actressWaterfall.getElementsByTag("a")) { + try { + movie.actresses.add( + Actress.create( + box.getElementsByTag("span").text(), + box.getElementsByTag("img").first().attr("src"), + box.attr("href") + ) + ); + } catch (Exception ignored) { + } } } } diff --git a/app/src/main/java/io/github/javiewer/view/ActressImageView.java b/app/src/main/java/io/github/javiewer/view/ActressImageView.java new file mode 100644 index 0000000..4f56c61 --- /dev/null +++ b/app/src/main/java/io/github/javiewer/view/ActressImageView.java @@ -0,0 +1,36 @@ +package io.github.javiewer.view; + +import android.content.Context; +import android.support.v4.content.res.ResourcesCompat; +import android.util.AttributeSet; +import android.widget.ImageView; + +import io.github.javiewer.R; + +/** + * Project: JAViewer + */ +public class ActressImageView extends ImageView { + + public ActressImageView(Context context) { + super(context); + } + + public ActressImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ActressImageView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (getDrawable() == null) { + setImageDrawable(ResourcesCompat.getDrawable(this.getResources(), R.drawable.ic_movie_actresses, null)); + } + + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/github/javiewer/view/ActressScaleImageView.java b/app/src/main/java/io/github/javiewer/view/ActressScaleImageView.java index 4663908..bca5354 100644 --- a/app/src/main/java/io/github/javiewer/view/ActressScaleImageView.java +++ b/app/src/main/java/io/github/javiewer/view/ActressScaleImageView.java @@ -26,7 +26,7 @@ public ActressScaleImageView(Context context, AttributeSet attrs, int defStyle) @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getDrawable() == null) { - setImageDrawable(ResourcesCompat.getDrawable(this.getResources(), R.drawable.ic_default_actresses, null)); + setImageDrawable(ResourcesCompat.getDrawable(this.getResources(), R.drawable.ic_movie_actresses, null)); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); diff --git a/app/src/main/java/io/github/javiewer/view/ScaleImageView.java b/app/src/main/java/io/github/javiewer/view/ScaleImageView.java index 991cf79..ff83e0b 100644 --- a/app/src/main/java/io/github/javiewer/view/ScaleImageView.java +++ b/app/src/main/java/io/github/javiewer/view/ScaleImageView.java @@ -24,10 +24,6 @@ public ScaleImageView(Context context, AttributeSet attrs, int defStyle) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { try { - - /*if (getDrawable() == null) { - setImageDrawable(ResourcesCompat.getDrawable(this.getResources(), R.drawable.ic_menu_actresses, null)); - }*/ int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); setMeasuredDimension(measuredWidth, measuredWidth); diff --git a/app/src/main/res/drawable/ic_default_actresses.xml b/app/src/main/res/drawable/ic_movie_actresses.xml similarity index 100% rename from app/src/main/res/drawable/ic_default_actresses.xml rename to app/src/main/res/drawable/ic_movie_actresses.xml diff --git a/app/src/main/res/drawable/ic_movie_genre.xml b/app/src/main/res/drawable/ic_movie_genre.xml new file mode 100644 index 0000000..fa405a6 --- /dev/null +++ b/app/src/main/res/drawable/ic_movie_genre.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_default_photo.xml b/app/src/main/res/drawable/ic_movie_photo.xml similarity index 100% rename from app/src/main/res/drawable/ic_default_photo.xml rename to app/src/main/res/drawable/ic_movie_photo.xml diff --git a/app/src/main/res/layout/card_actress.xml b/app/src/main/res/layout/card_actress.xml index 8c96a5d..4eacb7c 100644 --- a/app/src/main/res/layout/card_actress.xml +++ b/app/src/main/res/layout/card_actress.xml @@ -23,7 +23,7 @@ android:adjustViewBounds="true" android:scaleType="centerCrop" - android:src="@drawable/ic_default_actresses" /> + android:src="@drawable/ic_movie_actresses" /> + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/card_download.xml b/app/src/main/res/layout/card_download.xml index b308db8..279b8dd 100644 --- a/app/src/main/res/layout/card_download.xml +++ b/app/src/main/res/layout/card_download.xml @@ -1,11 +1,16 @@ + android:foreground="?android:attr/selectableItemBackground" + app:cardElevation="2dp"> diff --git a/app/src/main/res/layout/card_genre_movie.xml b/app/src/main/res/layout/card_genre_movie.xml new file mode 100644 index 0000000..0be4918 --- /dev/null +++ b/app/src/main/res/layout/card_genre_movie.xml @@ -0,0 +1,29 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_movie.xml b/app/src/main/res/layout/content_movie.xml index 387689a..c6ef3d8 100644 --- a/app/src/main/res/layout/content_movie.xml +++ b/app/src/main/res/layout/content_movie.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginTop="32dp" android:background="#FAFAFA" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="io.github.javiewer.activity.MovieActivity" @@ -13,15 +12,24 @@ + android:orientation="vertical" + android:paddingTop="32dp"> + android:id="@+id/movie_headers" + layout="@layout/content_movie_headers" /> + + + + diff --git a/app/src/main/res/layout/content_movie_actresses.xml b/app/src/main/res/layout/content_movie_actresses.xml new file mode 100644 index 0000000..18d0f14 --- /dev/null +++ b/app/src/main/res/layout/content_movie_actresses.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_movie_genre.xml b/app/src/main/res/layout/content_movie_genre.xml new file mode 100644 index 0000000..4d10772 --- /dev/null +++ b/app/src/main/res/layout/content_movie_genre.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_movie_headers.xml b/app/src/main/res/layout/content_movie_headers.xml new file mode 100644 index 0000000..8fb26ae --- /dev/null +++ b/app/src/main/res/layout/content_movie_headers.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_movie_info.xml b/app/src/main/res/layout/content_movie_info.xml deleted file mode 100644 index 9c400eb..0000000 --- a/app/src/main/res/layout/content_movie_info.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -