修改部分java代码

old
Administrator 5 years ago
parent ad9f40a665
commit bc8519720d
  1. 3
      .idea/codeStyles/Project.xml
  2. 8
      app/src/main/java/com/novel/read/Ext.kt
  3. 10
      app/src/main/java/com/novel/read/activity/NovelMainActivity.kt
  4. 6
      app/src/main/java/com/novel/read/fragment/BookFragment.kt
  5. 6
      app/src/main/java/com/novel/read/fragment/MoreFragment.kt
  6. 40
      app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.java
  7. 35
      app/src/main/java/com/novel/read/http/CommonHeadersInterceptor.kt
  8. 54
      app/src/main/java/com/novel/read/http/ServiceGenerator.java
  9. 49
      app/src/main/java/com/novel/read/http/ServiceGenerator.kt
  10. 2
      app/src/main/java/com/novel/read/model/db/BookChapterBean.java
  11. 4
      app/src/main/java/com/novel/read/utlis/DateUtli.java
  12. 30
      app/src/main/java/com/novel/read/utlis/TagColor.java
  13. 102
      app/src/main/java/com/novel/read/utlis/ToastUtil.java
  14. 51
      app/src/main/java/com/novel/read/utlis/VersionUtil.java
  15. 55
      app/src/main/java/com/novel/read/utlis/VersionUtil.kt

@ -1,8 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<AndroidXmlCodeStyleSettings>
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
</AndroidXmlCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>

@ -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()
}

@ -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()
}

@ -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())
}

@ -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()
}

@ -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());
}
}

@ -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())
}
}

@ -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> S createService(Class<S> serviceClass, final MyRequestType type) {
Retrofit retrofit = builderTEXT.build();
return retrofit.create(serviceClass);
}
public static String formatResponse(Object obj) {
return gson.toJson(obj);
}
}

@ -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 <S> createService(serviceClass: Class<S>, type: MyRequestType): S {
val retrofit = builderTEXT.build()
return retrofit.create(serviceClass)
}
fun formatResponse(obj: Any): String {
return gson.toJson(obj)
}
}

@ -5,7 +5,7 @@ import org.litepal.crud.LitePalSupport;
import java.io.Serializable;
/**
* Created by newbiechen on 17-5-10.
* Created by zlj
* 书的章节链接(作为下载的进度数据)
* 同时作为网络章节和本地章节 (没有找到更好分离两者的办法)
*/

@ -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);
}

@ -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<TagColor> getRandomColors(int size) {
List<TagColor> 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;
}
}

@ -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提示时<br/>
* 总开关关闭,传入true,显示;<br/>
* 总开关开启,传入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();
}
}

@ -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;
}
}

@ -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
}
}
Loading…
Cancel
Save