提交 2232d7db 编写于 作者: 门心叼龙's avatar 门心叼龙

code perfect

上级 34eb7215
...@@ -20,7 +20,9 @@ import java.util.ArrayList ...@@ -20,7 +20,9 @@ import java.util.ArrayList
*/ */
class NewsDetailDao(context: Context) { class NewsDetailDao(context: Context) {
private val mDatabase: SQLiteDatabase private val mDatabase: SQLiteDatabase
init {
mDatabase = NewsDBHelper.getInstance(context)!!.readableDatabase
}
val isEmpty: Boolean val isEmpty: Boolean
get() { get() {
val sql = "select * from " + NewsDBConfig.NewsDetail.TABLE_NAME val sql = "select * from " + NewsDBConfig.NewsDetail.TABLE_NAME
...@@ -30,10 +32,6 @@ class NewsDetailDao(context: Context) { ...@@ -30,10 +32,6 @@ class NewsDetailDao(context: Context) {
} else true } else true
} }
init {
mDatabase = NewsDBHelper.getInstance(context)!!.readableDatabase
}
fun addNewsDetail(type: Int, title: String, content: String): Boolean { fun addNewsDetail(type: Int, title: String, content: String): Boolean {
val values = ContentValues() val values = ContentValues()
values.put(NewsDBConfig.NewsDetail.CLUMN_TYPE_ID, type) values.put(NewsDBConfig.NewsDetail.CLUMN_TYPE_ID, type)
......
...@@ -16,7 +16,7 @@ abstract class BaseRefreshLayout(context: Context, attrs: AttributeSet) : SuperS ...@@ -16,7 +16,7 @@ abstract class BaseRefreshLayout(context: Context, attrs: AttributeSet) : SuperS
private var isEnableLoadMore = true//是否启用上拉加载更多 private var isEnableLoadMore = true//是否启用上拉加载更多
protected lateinit var mOnRefreshListener: OnRefreshListener//下拉刷新监听器 protected lateinit var mOnRefreshListener: OnRefreshListener//下拉刷新监听器
protected lateinit var mOnLoadMoreListener: OnLoadMoreListener//上拉加载更多监听器 protected lateinit var mOnLoadMoreListener: OnLoadMoreListener//上拉加载更多监听器
protected var mOnAutoLoadListener: OnAutoLoadListener? = null//自动加载的回调 protected lateinit var mOnAutoLoadListener: OnAutoLoadListener//自动加载的回调
interface OnRefreshListener { interface OnRefreshListener {
fun onRefresh() fun onRefresh()
......
...@@ -24,9 +24,9 @@ import com.refresh.lib.contract.PushContract ...@@ -24,9 +24,9 @@ import com.refresh.lib.contract.PushContract
</DaisyHeaderView> */ </DaisyHeaderView> */
class DaisyFooterView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs), PushContract { class DaisyFooterView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs), PushContract {
private var mTxtLoading: TextView? = null private lateinit var mTxtLoading: TextView
private var mImgDaisy: ImageView? = null private lateinit var mImgDaisy: ImageView
private var mRotation: ObjectAnimator? = null private lateinit var mRotation: ObjectAnimator
init { init {
initView(context) initView(context)
...@@ -36,29 +36,29 @@ class DaisyFooterView @JvmOverloads constructor(context: Context, attrs: Attribu ...@@ -36,29 +36,29 @@ class DaisyFooterView @JvmOverloads constructor(context: Context, attrs: Attribu
fun initView(context: Context) { fun initView(context: Context) {
LayoutInflater.from(context).inflate(R.layout.layout_daisy, this) LayoutInflater.from(context).inflate(R.layout.layout_daisy, this)
mTxtLoading = findViewById(R.id.txt_loading) mTxtLoading = findViewById(R.id.txt_loading)
mTxtLoading!!.text = "上拉加载更多..." mTxtLoading.text = "上拉加载更多..."
mImgDaisy = findViewById(R.id.img_daisy) mImgDaisy = findViewById(R.id.img_daisy)
mRotation = ObjectAnimator.ofFloat(mImgDaisy, "rotation", 0f, 360f).setDuration(800) mRotation = ObjectAnimator.ofFloat(mImgDaisy, "rotation", 0f, 360f).setDuration(800)
mRotation!!.repeatCount = ValueAnimator.INFINITE mRotation.repeatCount = ValueAnimator.INFINITE
mRotation!!.interpolator = LinearInterpolator() mRotation.interpolator = LinearInterpolator()
} }
override fun onPushEnable(enable: Boolean) { override fun onPushEnable(enable: Boolean) {
mTxtLoading!!.text = if (enable) "松开加载" else "上拉加载" mTxtLoading.text = if (enable) "松开加载" else "上拉加载"
} }
override fun onLoadMore() { override fun onLoadMore() {
mTxtLoading!!.text = "正在加载..." mTxtLoading.text = "正在加载..."
mRotation!!.start() mRotation.start()
} }
@RequiresApi(Build.VERSION_CODES.KITKAT) @RequiresApi(Build.VERSION_CODES.KITKAT)
fun setLoadMore(b: Boolean) { fun setLoadMore(b: Boolean) {
if (b) { if (b) {
mRotation!!.start() mRotation.start()
} else { } else {
mRotation!!.pause() mRotation.pause()
} }
} }
} }
...@@ -22,9 +22,9 @@ import com.refresh.lib.contract.PullContract ...@@ -22,9 +22,9 @@ import com.refresh.lib.contract.PullContract
</DaisyHeaderView> */ </DaisyHeaderView> */
class DaisyHeaderView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs), PullContract { class DaisyHeaderView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs), PullContract {
private var mTxtLoading: TextView? = null private lateinit var mTxtLoading: TextView
private var mImgDaisy: ImageView? = null private lateinit var mImgDaisy: ImageView
private var mRotation: ObjectAnimator? = null private lateinit var mRotation: ObjectAnimator
init { init {
initView(context) initView(context)
...@@ -34,29 +34,29 @@ class DaisyHeaderView @JvmOverloads constructor(context: Context, attrs: Attribu ...@@ -34,29 +34,29 @@ class DaisyHeaderView @JvmOverloads constructor(context: Context, attrs: Attribu
fun initView(context: Context) { fun initView(context: Context) {
LayoutInflater.from(context).inflate(R.layout.layout_daisy, this) LayoutInflater.from(context).inflate(R.layout.layout_daisy, this)
mTxtLoading = findViewById(R.id.txt_loading) mTxtLoading = findViewById(R.id.txt_loading)
mTxtLoading!!.text = "下拉刷新" mTxtLoading.text = "下拉刷新"
mImgDaisy = findViewById(R.id.img_daisy) mImgDaisy = findViewById(R.id.img_daisy)
mRotation = ObjectAnimator.ofFloat(mImgDaisy, "rotation", 0f, 360f).setDuration(800) mRotation = ObjectAnimator.ofFloat(mImgDaisy, "rotation", 0f, 360f).setDuration(800)
mRotation!!.repeatCount = ValueAnimator.INFINITE mRotation.repeatCount = ValueAnimator.INFINITE
mRotation!!.interpolator = LinearInterpolator() mRotation.interpolator = LinearInterpolator()
} }
override fun onPullEnable(enable: Boolean) { override fun onPullEnable(enable: Boolean) {
mTxtLoading!!.text = if (enable) "松开刷新" else "下拉刷新" mTxtLoading.text = if (enable) "松开刷新" else "下拉刷新"
} }
override fun onRefresh() { override fun onRefresh() {
mTxtLoading!!.text = "正在刷新" mTxtLoading.text = "正在刷新"
mRotation!!.start() mRotation.start()
} }
fun setRefreshing(b: Boolean) { fun setRefreshing(b: Boolean) {
if (b) { if (b) {
mRotation!!.start() mRotation.start()
} else { } else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mRotation!!.pause() mRotation.pause()
} }
} }
} }
......
package com.refresh.lib package com.refresh.lib
import android.content.Context import android.content.Context
import android.os.Build
import android.util.AttributeSet import android.util.AttributeSet
import androidx.annotation.RequiresApi
/** /**
* Description: <小菊花样式的刷新控件><br> * Description: <小菊花样式的刷新控件><br>
...@@ -9,10 +11,10 @@ import android.util.AttributeSet ...@@ -9,10 +11,10 @@ import android.util.AttributeSet
* Date: 2019/2/25<br> * Date: 2019/2/25<br>
* Version: V1.0.0<br> * Version: V1.0.0<br>
* Update: <br> * Update: <br>
</小菊花样式的刷新控件> */ */
class DaisyRefreshLayout(context: Context, attrs: AttributeSet) : class DaisyRefreshLayout(context: Context, attrs: AttributeSet) :
BaseRefreshLayout(context, attrs) { BaseRefreshLayout(context, attrs) {
private val mDaisyHeaderView: DaisyHeaderView? private val mDaisyHeaderView: DaisyHeaderView
private val mDaisyFooterView: DaisyFooterView private val mDaisyFooterView: DaisyFooterView
override var isRefreshing: Boolean override var isRefreshing: Boolean
get() = super.isRefreshing get() = super.isRefreshing
...@@ -60,6 +62,7 @@ class DaisyRefreshLayout(context: Context, attrs: AttributeSet) : ...@@ -60,6 +62,7 @@ class DaisyRefreshLayout(context: Context, attrs: AttributeSet) :
mDaisyHeaderView?.onRefresh() mDaisyHeaderView?.onRefresh()
} }
@RequiresApi(Build.VERSION_CODES.KITKAT)
override fun setLoadMore(loadMore: Boolean) { override fun setLoadMore(loadMore: Boolean) {
mDaisyFooterView.setLoadMore(loadMore) mDaisyFooterView.setLoadMore(loadMore)
super.setLoadMore(loadMore) super.setLoadMore(loadMore)
......
...@@ -6,7 +6,7 @@ package com.refresh.lib.contract ...@@ -6,7 +6,7 @@ package com.refresh.lib.contract
* Date: 2019/2/25<br> * Date: 2019/2/25<br>
* Version: V1.0.0<br> * Version: V1.0.0<br>
* Update: <br> * Update: <br>
</下拉刷新的协议> */ */
interface PullContract { interface PullContract {
/** /**
* 手指上滑下滑的回调 * 手指上滑下滑的回调
......
...@@ -6,7 +6,7 @@ package com.refresh.lib.contract ...@@ -6,7 +6,7 @@ package com.refresh.lib.contract
* Date: 2019/2/25<br> * Date: 2019/2/25<br>
* Version: V1.0.0<br> * Version: V1.0.0<br>
* Update: <br> * Update: <br>
</上拉加载更多的协议> */ */
interface PushContract { interface PushContract {
/** /**
* 手指上滑下滑的回调 * 手指上滑下滑的回调
......
...@@ -13,7 +13,7 @@ import com.fly.tour.me.contract.NewsDetailAddContract ...@@ -13,7 +13,7 @@ import com.fly.tour.me.contract.NewsDetailAddContract
* Update: <br> * Update: <br>
*/ */
class NewsDetailAddModel(content: Context) : BaseModel(content), NewsDetailAddContract.Model { class NewsDetailAddModel(content: Context) : BaseModel(content), NewsDetailAddContract.Model {
var mNewsDetailDao: NewsDetailDao = NewsDetailDao(context) private val mNewsDetailDao: NewsDetailDao by lazy { NewsDetailDao(context) }
override fun addNewsDetail(type: Int, title: String, content: String): Boolean { override fun addNewsDetail(type: Int, title: String, content: String): Boolean {
return mNewsDetailDao.addNewsDetail(type, title, content) return mNewsDetailDao.addNewsDetail(type, title, content)
} }
......
...@@ -13,7 +13,7 @@ import com.fly.tour.me.contract.NewsTypeAddContract ...@@ -13,7 +13,7 @@ import com.fly.tour.me.contract.NewsTypeAddContract
* Update: <br> * Update: <br>
*/ */
class NewsTypeAddModel(context: Context) : BaseModel(context), NewsTypeAddContract.Model { class NewsTypeAddModel(context: Context) : BaseModel(context), NewsTypeAddContract.Model {
var mNewsTypeDao: NewsTypeDao = NewsTypeDao(context) private val mNewsTypeDao: NewsTypeDao by lazy { NewsTypeDao(context) }
override fun addNewsType(type: String): Boolean { override fun addNewsType(type: String): Boolean {
return mNewsTypeDao.addNewsType(type) return mNewsTypeDao.addNewsType(type)
} }
......
...@@ -14,7 +14,7 @@ import com.fly.tour.me.contract.NewsTypeListContract ...@@ -14,7 +14,7 @@ import com.fly.tour.me.contract.NewsTypeListContract
* Update: <br> * Update: <br>
*/ */
class NewsTypeListModel(context: Context) : BaseModel(context), NewsTypeListContract.Model { class NewsTypeListModel(context: Context) : BaseModel(context), NewsTypeListContract.Model {
private var mNewsTypeDao: NewsTypeDao = NewsTypeDao(context) private val mNewsTypeDao: NewsTypeDao by lazy { NewsTypeDao(context) }
override fun getListNewsType(): List<NewsType>? { override fun getListNewsType(): List<NewsType>? {
return mNewsTypeDao.getListNewsType() return mNewsTypeDao.getListNewsType()
} }
......
...@@ -6,13 +6,6 @@ import com.fly.tour.db.dao.NewsDetailDao ...@@ -6,13 +6,6 @@ import com.fly.tour.db.dao.NewsDetailDao
import com.fly.tour.db.entity.NewsDetail import com.fly.tour.db.entity.NewsDetail
import com.fly.tour.news.contract.NewsDetailContract import com.fly.tour.news.contract.NewsDetailContract
/**
* Description: <NewsDetailModel><br>
* Author: mxdl<br>
* Date: 2020/2/17<br>
* Version: V1.0.0<br>
* Update: <br>
*/
/** /**
* Description: <NewsDetailModel><br> * Description: <NewsDetailModel><br>
* Author: mxdl<br> * Author: mxdl<br>
...@@ -21,7 +14,7 @@ import com.fly.tour.news.contract.NewsDetailContract ...@@ -21,7 +14,7 @@ import com.fly.tour.news.contract.NewsDetailContract
* Update: <br> * Update: <br>
*/ */
class NewsDetailModel(context: Context) : BaseModel(context), NewsDetailContract.Model { class NewsDetailModel(context: Context) : BaseModel(context), NewsDetailContract.Model {
private var mNewsDetailDao: NewsDetailDao = NewsDetailDao(context) private val mNewsDetailDao: NewsDetailDao by lazy { NewsDetailDao(context) }
override fun getNewsDetailById(id: Int): NewsDetail? { override fun getNewsDetailById(id: Int): NewsDetail? {
return mNewsDetailDao.getNewsDetailById(id) return mNewsDetailDao.getNewsDetailById(id)
} }
......
...@@ -6,13 +6,6 @@ import com.fly.tour.db.dao.NewsDetailDao ...@@ -6,13 +6,6 @@ import com.fly.tour.db.dao.NewsDetailDao
import com.fly.tour.db.entity.NewsDetail import com.fly.tour.db.entity.NewsDetail
import com.fly.tour.news.contract.NewsListContract import com.fly.tour.news.contract.NewsListContract
/**
* Description: <NewsListModel><br>
* Author: mxdl<br>
* Date: 2020/2/16<br>
* Version: V1.0.0<br>
* Update: <br>
*/
/** /**
* Description: <NewsListModel><br> * Description: <NewsListModel><br>
* Author: mxdl<br> * Author: mxdl<br>
...@@ -21,7 +14,7 @@ import com.fly.tour.news.contract.NewsListContract ...@@ -21,7 +14,7 @@ import com.fly.tour.news.contract.NewsListContract
* Update: <br> * Update: <br>
*/ */
class NewsListModel(context:Context) : BaseModel(context),NewsListContract.Model { class NewsListModel(context:Context) : BaseModel(context),NewsListContract.Model {
private var mDetailDao = NewsDetailDao(context) private val mDetailDao by lazy { NewsDetailDao(context)}
override fun getListNewsByType(type: Int): List<NewsDetail>? { override fun getListNewsByType(type: Int): List<NewsDetail>? {
return mDetailDao.getListNewsByType(type) return mDetailDao.getListNewsByType(type)
} }
......
...@@ -2,11 +2,18 @@ package com.fly.tour.test ...@@ -2,11 +2,18 @@ package com.fly.tour.test
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import com.fly.tour.test.view.MyView2
import com.fly.tour.test.view.Person1
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
btn.setOnClickListener {
//view.test()
}
} }
} }
package com.fly.tour.test;
import com.fly.tour.common.util.ToastUtil;
/**
* Description: <Test><br>
* Author: mxdl<br>
* Date: 2020/2/19<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class Test {
public static void main(String[] args) {
ToastUtil.INSTANCE.showToast("ok");
//System.out.println("ok");
}
}
package com.fly.tour.test
import com.fly.tour.common.util.ToastUtil
/**
* Description: <Test1><br>
* Author: mxdl<br>
* Date: 2020/2/19<br>
* Version: V1.0.0<br>
* Update: <br>
*/
/**
* Description: <Test1><br>
* Author: mxdl<br>
* Date: 2020/2/19<br>
* Version: V1.0.0<br>
* Update: <br>
*/
class Test1 {
}
fun main(args: Array<String>) {
ToastUtil.showToast("ok")
}
\ No newline at end of file
package com.fly.tour.test.view
import android.content.Context
import android.util.AttributeSet
import android.view.View
/**
* Description: <MyView><br></br>
* Author: mxdl<br></br>
* Date: 2020/2/20<br></br>
* Version: V1.0.0<br></br>
* Update: <br></br>
</MyView> */
class MyView : View {
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context,attrs,defStyleAttr) {}
}
package com.fly.tour.test.view
import android.content.Context
import android.util.AttributeSet
import android.view.View
/**
* Description: <MyView><br></br>
* Author: mxdl<br></br>
* Date: 2020/2/20<br></br>
* Version: V1.0.0<br></br>
* Update: <br></br>
</MyView> */
class MyView1 @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr)
package com.fly.tour.test.view
import android.content.Context
import android.util.AttributeSet
import android.view.View
/**
* Description: <MyView><br></br>
* Author: mxdl<br></br>
* Date: 2020/2/20<br></br>
* Version: V1.0.0<br></br>
* Update: <br></br>
</MyView> */
class MyView2 : View {
init {
println("MyView2 init")
}
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : super(context, attrs, defStyleAttr){
println("MyView2 constructor")
}
fun test(){
println("Hello World!")
}
}
package com.fly.tour.test.view
/**
* Description: <Person1><br>
* Author: mxdl<br>
* Date: 2020/2/20<br>
* Version: V1.0.0<br>
* Update: <br>
*/
class Person{
var username:String? = null
var age:Int = 16
}
\ No newline at end of file
package com.fly.tour.test.view;
/**
* Description: <Person1><br>
* Author: mxdl<br>
* Date: 2020/2/20<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class Person1 {
int age;
String name;
public Person1(int age, String name) {
this.age = age;
this.name = name;
}
}
package com.fly.tour.test.view.java;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
/**
* Description: <MyView><br>
* Author: mxdl<br>
* Date: 2020/2/20<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyView extends View {
public MyView(Context context) {
super(context);
}
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
package com.fly.tour.test.view.java;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
/**
* Description: <MyView><br>
* Author: mxdl<br>
* Date: 2020/2/20<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyView1 extends View {
public MyView1(Context context) {
this(context,null);
}
public MyView1(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public MyView1(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> xmlns:android="http://schemas.android.com/apk/res/android">
<Button
<TextView android:id="@+id/btn"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"/>
android:text="Hello World!" </LinearLayout>
app:layout_constraintBottom_toBottomOf="parent" \ No newline at end of file
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册