diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 5c82789..43fd926 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,8 +1,5 @@ - - diff --git a/app/src/main/java/com/novel/read/Ext.kt b/app/src/main/java/com/novel/read/Ext.kt new file mode 100644 index 0000000..32e739f --- /dev/null +++ b/app/src/main/java/com/novel/read/Ext.kt @@ -0,0 +1,8 @@ +package com.novel.read + +import android.content.Context +import android.widget.Toast + +fun Context.showToast(msg:String){ + Toast.makeText(this,msg,Toast.LENGTH_SHORT).show() +} \ No newline at end of file diff --git a/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt b/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt index e269a6b..0ca711f 100644 --- a/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt +++ b/app/src/main/java/com/novel/read/activity/NovelMainActivity.kt @@ -1,12 +1,9 @@ package com.novel.read.activity import android.annotation.SuppressLint -import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent -import android.net.Uri import android.os.Bundle -import android.text.TextUtils import android.util.Log import android.view.KeyEvent import android.view.View @@ -22,11 +19,8 @@ import com.novel.read.fragment.RecommendFragment import com.novel.read.fragment.StackFragment import com.novel.read.http.AccountManager import com.novel.read.model.db.dbManage.BookRepository -import com.novel.read.utlis.DateUtli +import com.novel.read.showToast import com.novel.read.utlis.SpUtil -import com.novel.read.utlis.ToastUtil -import com.novel.read.utlis.VersionUtil -import com.novel.read.widget.dialog.AppraiseDialog import com.squareup.otto.Subscribe import kotlinx.android.synthetic.main.activity_main.* @@ -130,7 +124,7 @@ class NovelMainActivity : NovelBaseActivity() { val secondTime = System.currentTimeMillis() if (secondTime - firstTime > 1000) { firstTime = secondTime - ToastUtil.show(this@NovelMainActivity, "再次点击退出界面") + showToast("再次点击退出界面") } else { finish() } diff --git a/app/src/main/java/com/novel/read/fragment/BookFragment.kt b/app/src/main/java/com/novel/read/fragment/BookFragment.kt index d214b4d..88a72eb 100644 --- a/app/src/main/java/com/novel/read/fragment/BookFragment.kt +++ b/app/src/main/java/com/novel/read/fragment/BookFragment.kt @@ -21,10 +21,10 @@ import com.novel.read.model.db.BookRecordBean import com.novel.read.model.db.CollBookBean import com.novel.read.model.db.dbManage.BookRepository import com.novel.read.model.protocol.BookDetailResp +import com.novel.read.showToast import com.novel.read.utlis.LocalManageUtil import com.novel.read.utlis.RxUtils import com.novel.read.utlis.SpUtil -import com.novel.read.utlis.ToastUtil import com.squareup.otto.Subscribe import io.reactivex.Single import io.reactivex.SingleObserver @@ -88,7 +88,7 @@ class BookFragment : NovelBaseFragment() { ) } R.id.edit_book -> if (mList.size == 0) { //没书的时候提醒用户不能编辑 - ToastUtil.show(activity, getString(R.string.please_add_book)) + activity!!.showToast(getString(R.string.please_add_book)) } else { mAdapter!!.setEdit(true) tv_cancel.visibility = View.VISIBLE @@ -135,7 +135,7 @@ class BookFragment : NovelBaseFragment() { Log.e("count", "setOnClick: $count") } } - ToastUtil.show(activity, getString(R.string.delete_success)) + activity!!.showToast( getString(R.string.delete_success)) EventManager.instance.postEvent(HideBottomBarEvent(false)) updateBook(UpdateBookEvent()) } diff --git a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt index 5d5bee3..0dc23aa 100644 --- a/app/src/main/java/com/novel/read/fragment/MoreFragment.kt +++ b/app/src/main/java/com/novel/read/fragment/MoreFragment.kt @@ -13,7 +13,7 @@ import com.novel.read.activity.NovelSettingActivity import com.novel.read.base.NovelBaseFragment import com.novel.read.constants.Constant import com.novel.read.event.ReStartEvent -import com.novel.read.utlis.ToastUtil +import com.novel.read.showToast import com.novel.read.utlis.VersionUtil import com.novel.read.widget.dialog.AppraiseDialog import com.squareup.otto.Subscribe @@ -55,7 +55,7 @@ class MoreFragment : NovelBaseFragment() { tv_appraise.setOnClickListener { val dialog = AppraiseDialog(activity!!) dialog.appraiseDialog(View.OnClickListener { - goToMarket(activity!!, VersionUtil.getPackage(activity)) + goToMarket(activity!!, VersionUtil.getPackage(activity!!)) dialog.dismiss() }) dialog.show() @@ -113,7 +113,7 @@ class MoreFragment : NovelBaseFragment() { if (goToMarket.resolveActivity(context.packageManager) != null) { //有浏览器 context.startActivity(goToMarket) } else { - ToastUtil.show(context, "未检测到Google应用商店") + context.showToast("未检测到Google应用商店") } e.printStackTrace() } diff --git a/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java b/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java deleted file mode 100644 index 053d655..0000000 --- a/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.novel.read.http; -import androidx.annotation.NonNull; - -import com.common_lib.base.utils.SecurityUtils; -import com.novel.read.constants.Constant; -import com.novel.read.utlis.SpUtil; - -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; - -import okhttp3.Interceptor; -import okhttp3.Request; -import okhttp3.Response; - -/** - * Created by zlj on 2019/3/1. - */ -public class CommonHeadersInterceptor implements Interceptor { - - @NotNull - @Override - public Response intercept(@NonNull Interceptor.Chain chain) throws IOException { - Request request = chain.request(); - Request.Builder builder = request.newBuilder(); - - String authKey = "Android"; - String timeStamp = String.valueOf(System.currentTimeMillis() / 1000); - String uid = SpUtil.getStringValue(Constant.Uid, "1"); - builder.addHeader("Content-Type", "application/json"); - builder.addHeader("UID", uid); - builder.addHeader("AUTHKEY", authKey); - builder.addHeader("TIMESTAMP", timeStamp); - - builder.addHeader("SIGN", SecurityUtils.getInstance().MD5Decode(authKey + timeStamp).toUpperCase()); - - - return chain.proceed(builder.build()); - } -} diff --git a/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.kt b/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.kt new file mode 100644 index 0000000..a29d6d2 --- /dev/null +++ b/app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.kt @@ -0,0 +1,35 @@ +package com.novel.read.http + +import com.common_lib.base.utils.SecurityUtils +import com.novel.read.constants.Constant +import com.novel.read.utlis.SpUtil + +import java.io.IOException + +import okhttp3.Interceptor +import okhttp3.Request +import okhttp3.Response + +/** + * Created by zlj on 2019/3/1. + */ +class CommonHeadersInterceptor : Interceptor { + + @Throws(IOException::class) + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + val builder = request.newBuilder() + + val authKey = "Android" + val timeStamp = (System.currentTimeMillis() / 1000).toString() + val uid = SpUtil.getStringValue(Constant.Uid, "1") + builder.addHeader("Content-Type", "application/json") + builder.addHeader("UID", uid) + builder.addHeader("AUTHKEY", authKey) + builder.addHeader("TIMESTAMP", timeStamp) + + builder.addHeader("SIGN", SecurityUtils.getInstance().MD5Decode(authKey + timeStamp).toUpperCase()) + + return chain.proceed(builder.build()) + } +} diff --git a/app/src/main/java/com/novel/read/http/ServiceGenerator.java b/app/src/main/java/com/novel/read/http/ServiceGenerator.java deleted file mode 100644 index c6700e2..0000000 --- a/app/src/main/java/com/novel/read/http/ServiceGenerator.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.novel.read.http; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.mango.mangolib.http.GsonUTCdateAdapter; -import com.mango.mangolib.http.MyRequestType; -import com.mango.mangolib.http.ResponseConverterFactory; - -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import okhttp3.OkHttpClient; -import retrofit2.Retrofit; -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; -import retrofit2.converter.gson.GsonConverterFactory; - - -public class ServiceGenerator { - private static final String API_BASE_URL_TEXT = "http://novel.duoduvip.com/"; - - private static Gson gson = new GsonBuilder() - .setPrettyPrinting() - .registerTypeAdapter(Date.class, new GsonUTCdateAdapter()).create(); - - - private static Retrofit.Builder builderTEXT = new Retrofit.Builder() - .baseUrl(API_BASE_URL_TEXT) - .client(getOkHttp()) - .addConverterFactory(ResponseConverterFactory.Companion.create()) - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) - .addConverterFactory(GsonConverterFactory.create(gson)); - - private static OkHttpClient getOkHttp() { - return new OkHttpClient() - .newBuilder() - .addInterceptor(new CommonHeadersInterceptor()) - .connectTimeout(15, TimeUnit.SECONDS) - .writeTimeout(15, TimeUnit.SECONDS) - .readTimeout(15, TimeUnit.SECONDS) - .build(); - } - - private ServiceGenerator() { - } - - public static S createService(Class serviceClass, final MyRequestType type) { - Retrofit retrofit = builderTEXT.build(); - return retrofit.create(serviceClass); - } - - public static String formatResponse(Object obj) { - return gson.toJson(obj); - } -} diff --git a/app/src/main/java/com/novel/read/http/ServiceGenerator.kt b/app/src/main/java/com/novel/read/http/ServiceGenerator.kt new file mode 100644 index 0000000..b17c361 --- /dev/null +++ b/app/src/main/java/com/novel/read/http/ServiceGenerator.kt @@ -0,0 +1,49 @@ +package com.novel.read.http + +import com.google.gson.GsonBuilder +import com.mango.mangolib.http.GsonUTCdateAdapter +import com.mango.mangolib.http.MyRequestType +import com.mango.mangolib.http.ResponseConverterFactory + +import java.util.Date +import java.util.concurrent.TimeUnit + +import okhttp3.OkHttpClient +import retrofit2.Retrofit +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory +import retrofit2.converter.gson.GsonConverterFactory + + +object ServiceGenerator { + private const val API_BASE_URL_TEXT = "http://novel.duoduvip.com/" + + private val gson = GsonBuilder() + .setPrettyPrinting() + .registerTypeAdapter(Date::class.java, GsonUTCdateAdapter()).create() + + + private val builderTEXT = Retrofit.Builder() + .baseUrl(API_BASE_URL_TEXT) + .client(okHttp) + .addConverterFactory(ResponseConverterFactory.create()) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) + + private val okHttp: OkHttpClient + get() = OkHttpClient() + .newBuilder() + .addInterceptor(CommonHeadersInterceptor()) + .connectTimeout(15, TimeUnit.SECONDS) + .writeTimeout(15, TimeUnit.SECONDS) + .readTimeout(15, TimeUnit.SECONDS) + .build() + + fun createService(serviceClass: Class, type: MyRequestType): S { + val retrofit = builderTEXT.build() + return retrofit.create(serviceClass) + } + + fun formatResponse(obj: Any): String { + return gson.toJson(obj) + } +} diff --git a/app/src/main/java/com/novel/read/model/db/BookChapterBean.java b/app/src/main/java/com/novel/read/model/db/BookChapterBean.java index c9dc450..a325c20 100644 --- a/app/src/main/java/com/novel/read/model/db/BookChapterBean.java +++ b/app/src/main/java/com/novel/read/model/db/BookChapterBean.java @@ -5,7 +5,7 @@ import org.litepal.crud.LitePalSupport; import java.io.Serializable; /** - * Created by newbiechen on 17-5-10. + * Created by zlj * 书的章节链接(作为下载的进度数据) * 同时作为网络章节和本地章节 (没有找到更好分离两者的办法) */ diff --git a/app/src/main/java/com/novel/read/utlis/DateUtli.java b/app/src/main/java/com/novel/read/utlis/DateUtli.java index dd258af..089b1f8 100644 --- a/app/src/main/java/com/novel/read/utlis/DateUtli.java +++ b/app/src/main/java/com/novel/read/utlis/DateUtli.java @@ -61,11 +61,7 @@ public class DateUtli { if (dayOfMonth == todayOfMonth) {//表示是同一周 int dayOfWeek = otherCalendar.get(Calendar.DAY_OF_WEEK); if (dayOfWeek != 1) {//判断当前是不是星期日 如想显示为:周日 12:09 可去掉此判断 -// if (flag==1) { result = dayNames[otherCalendar.get(Calendar.DAY_OF_WEEK) - 1]; -// }else{ -// result = dayNames[otherCalendar.get(Calendar.DAY_OF_WEEK) - 1] + getHourAndMin(timesamp); -// } } else { result = getTime(timesamp, timeFormat); } diff --git a/app/src/main/java/com/novel/read/utlis/TagColor.java b/app/src/main/java/com/novel/read/utlis/TagColor.java deleted file mode 100644 index 4be00cb..0000000 --- a/app/src/main/java/com/novel/read/utlis/TagColor.java +++ /dev/null @@ -1,30 +0,0 @@ - -package com.novel.read.utlis; - -import android.graphics.Color; - - -import com.novel.read.constants.Constant; - -import java.util.ArrayList; -import java.util.List; - -/** - */ -public class TagColor { - - public int borderColor = Color.parseColor("#49C120"); - public int backgroundColor = Color.parseColor("#49C120"); - public int textColor = Color.WHITE; - - public static List getRandomColors(int size) { - - List list = new ArrayList<>(); - for (int i = 0; i < size; i++) { - TagColor color = new TagColor(); - color.borderColor = color.backgroundColor = Constant.tagColors[i % Constant.tagColors.length]; - list.add(color); - } - return list; - } -} diff --git a/app/src/main/java/com/novel/read/utlis/ToastUtil.java b/app/src/main/java/com/novel/read/utlis/ToastUtil.java deleted file mode 100644 index 8cf033e..0000000 --- a/app/src/main/java/com/novel/read/utlis/ToastUtil.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.novel.read.utlis; - -import android.content.Context; -import android.os.Looper; -import android.os.SystemClock; -import android.widget.Toast; - -public class ToastUtil { - - private static Toast toast; - /** - * 当前工具类的总开关 - */ - private static boolean isAllowShow = true; - - /** - * 功能:开关(isAllowShow开启后,此方法功能可用) - * - * @param context - * @param msg - */ - public static void show(Context context, String msg) { - if (!isAllowShow) { - return; - } - // 开关开启后才往下执行 - if (toast == null) { - if (context == null) { - return; - } - toast = Toast.makeText(context, msg, 0); - } else { - toast.setText(msg); - } - toast.show(); - } - - public static void show(Context context, int msg) { - if (!isAllowShow) { - return; - } - // 开关开启后才往下执行 - if (toast == null) { - if (context == null) { - return; - } - toast = Toast.makeText(context, msg, 0); - } else { - toast.setText(msg); - } - toast.show(); - } - - /** - * 功能:上面方法的增强版,当只需要显示部分Toast提示时,
- * 总开关关闭,传入true,显示;
- * 总开关开启,传入false,关闭 - * - * @param context - * @param msg - * @param flag 开关状态 - */ - public static void show(Context context, String msg, boolean flag) { - if (!flag) { - return; - } - if (!isAllowShow && !flag) { - return; - } - // 开关开启后才往下执行 - if (toast == null) { - toast = Toast.makeText(context, msg, 0); - } else { - toast.setText(msg); - } - toast.show(); - } - - /** - * 功能:一直显示Toast - * - * @param context - * @param msg - * @param flag - */ - public static void alwaysShow(final Context context, final String msg, final boolean flag) { - new Thread() { - public void run() { - while (true) { - Looper.prepare(); - SystemClock.sleep(3000); -// show(context, msg, flag); - Toast.makeText(context, msg, 0).show(); - Looper.loop(); - } - } - - ; - }.start(); - - } -} diff --git a/app/src/main/java/com/novel/read/utlis/VersionUtil.java b/app/src/main/java/com/novel/read/utlis/VersionUtil.java deleted file mode 100644 index c72e880..0000000 --- a/app/src/main/java/com/novel/read/utlis/VersionUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.novel.read.utlis; - -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; - -public class VersionUtil { - - public static int getPackageCode(Context context) { - PackageManager manager = context.getPackageManager(); - int code = 0; - try { - PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); - code = info.versionCode; - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - return code; - } - public static String getPackageName(Context context) { - PackageManager manager = context.getPackageManager(); - String name = null; - try { - PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); - name = info.versionName; - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - - return name; - } - - /** - * [获取应用程序版本名称信息] - * @param context - * @return 当前应用的版本名称 - */ - public static String getPackage(Context context) { - try { - PackageManager packageManager = context.getPackageManager(); - PackageInfo packageInfo = packageManager.getPackageInfo( - context.getPackageName(), 0); - return packageInfo.packageName; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - -} diff --git a/app/src/main/java/com/novel/read/utlis/VersionUtil.kt b/app/src/main/java/com/novel/read/utlis/VersionUtil.kt new file mode 100644 index 0000000..a88c30b --- /dev/null +++ b/app/src/main/java/com/novel/read/utlis/VersionUtil.kt @@ -0,0 +1,55 @@ +package com.novel.read.utlis + +import android.content.Context +import android.content.pm.PackageInfo +import android.content.pm.PackageManager + +object VersionUtil { + + fun getPackageCode(context: Context): Int { + val manager = context.packageManager + var code = 0 + try { + val info = manager.getPackageInfo(context.packageName, 0) + code = info.versionCode + } catch (e: PackageManager.NameNotFoundException) { + e.printStackTrace() + } + + return code + } + + fun getPackageName(context: Context): String? { + val manager = context.packageManager + var name: String? = null + try { + val info = manager.getPackageInfo(context.packageName, 0) + name = info.versionName + } catch (e: PackageManager.NameNotFoundException) { + e.printStackTrace() + } + + return name + } + + /** + * [获取应用程序版本名称信息] + * @param context + * @return 当前应用的版本名称 + */ + fun getPackage(context: Context): String? { + try { + val packageManager = context.packageManager + val packageInfo = packageManager.getPackageInfo( + context.packageName, 0 + ) + return packageInfo.packageName + } catch (e: Exception) { + e.printStackTrace() + } + + return null + } + + +}