Skip to content

Commit

Permalink
arch转kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
K0170016 authored and K0170016 committed Jun 25, 2019
1 parent 76d6ecd commit 8825ed5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import com.huyingbao.core.base.BaseView
*/
abstract class BaseCommonDialog : AppCompatDialogFragment(), BaseView {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
//注意此处android.R.id.content
return inflater.inflate(getLayoutId(), dialog!!.window!!.findViewById(android.R.id.content), false)
//注意此处android.R.id.content,配合onStart()方法,使布局文件中背景值和尺寸值生效
return inflater.inflate(getLayoutId(), dialog?.window?.findViewById(android.R.id.content), false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand All @@ -30,9 +30,9 @@ abstract class BaseCommonDialog : AppCompatDialogFragment(), BaseView {
* Dialog对应的布局文件中背景值和尺寸值生效
*/
override fun onStart() {
val window = dialog!!.window
window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val window = dialog?.window
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
window?.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
super.onStart()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ abstract class BaseRxDialog<T : ViewModel> : RxFluxDialog<T>(), BaseView {
lateinit var commonActionCreator: CommonActionCreator

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
//注意此处android.R.id.content
return inflater.inflate(getLayoutId(), dialog!!.window!!.findViewById(android.R.id.content), false)
//注意此处android.R.id.content,配合onStart()方法,使布局文件中背景值和尺寸值生效
return inflater.inflate(getLayoutId(), dialog?.window?.findViewById(android.R.id.content), false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand All @@ -34,9 +34,9 @@ abstract class BaseRxDialog<T : ViewModel> : RxFluxDialog<T>(), BaseView {
* Dialog对应的布局文件中背景值和尺寸值生效
*/
override fun onStart() {
val window = dialog!!.window
window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val window = dialog?.window
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
window?.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
super.onStart()
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
//package com.huyingbao.core.base.fragment
//
//import android.os.Bundle
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.databinding.DataBindingUtil
//import androidx.databinding.ViewDataBinding
//import androidx.lifecycle.ViewModel
//import com.huyingbao.core.arch.utils.autoCleared
//
//
///**
// * 使用DataBinding的Fragment
// *
// * Created by liujunfeng on 2019/6/10.
// */
//abstract class BaseRxBindFragment<T : ViewModel, Y : ViewDataBinding> : BaseRxFragment<T>() {
// /**
// * 根据Fragment动态清理和获取binding对象
// */
// var binding by autoCleared<Y?>()
//
// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
// binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false)
// return binding?.root!!
// }
//}
package com.huyingbao.core.base.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import com.huyingbao.core.arch.utils.autoCleared


/**
* 使用DataBinding的Fragment
*
* Created by liujunfeng on 2019/6/10.
*/
abstract class BaseRxBindFragment<T : ViewModel, Y : ViewDataBinding> : BaseRxFragment<T>() {
/**
* 根据Fragment动态清理和获取binding对象
*/
var binding by autoCleared<Y?>()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false)
return binding?.root!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ abstract class BaseRxFragment<T : ViewModel> : RxFluxFragment<T>(), BaseView {
@Inject
lateinit var commonActionCreator: CommonActionCreator

private var mBackAble: Boolean = false
private var mTitle: CharSequence? = null
private var backAble: Boolean = false
private var title: CharSequence? = null

override fun onAttach(context: Context) {
super.onAttach(context)
Expand All @@ -48,7 +48,7 @@ abstract class BaseRxFragment<T : ViewModel> : RxFluxFragment<T>(), BaseView {
//从隐藏转为非隐藏的时候调用
//当前页面显示时,显示对应的标题
if (!hidden) {
setTitle(mTitle, mBackAble)
setTitle(title, backAble)
}
}

Expand All @@ -62,18 +62,18 @@ abstract class BaseRxFragment<T : ViewModel> : RxFluxFragment<T>(), BaseView {
if (activity == null) {
return
}
mBackAble = backAble
mTitle = title
this.backAble = backAble
this.title = title
val supportActionBar = (activity as AppCompatActivity).supportActionBar
if (activity !is AppCompatActivity || supportActionBar == null) {
//设置标题
activity!!.title = mTitle
activity?.title = this.title
return
}
//显示标题
supportActionBar.setDisplayShowTitleEnabled(true)
//设置标题
supportActionBar.title = mTitle
supportActionBar.title = this.title
//显示右侧返回图标
if (backAble) {
//显示Home按钮
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import javax.inject.Singleton
class CommonActionCreator @Inject
constructor(rxDispatcher: RxDispatcher, rxActionManager: RxActionManager) : RxActionCreator(rxDispatcher, rxActionManager) {
/**
* [RxActionManager]移除[RxAction],停止对应的[Disposable],
* 被观察者[Observable]正在运行的方法会被停止。
* [RxActionManager]移除[RxAction],停止对应的[Disposable],被观察者[Observable]正在运行的方法会被停止。
*/
fun removeRxAction(tag: String) {
removeRxAction(newRxAction(tag))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class CommonLoadingDialog : BaseCommonDialog() {
}

override fun afterCreate(savedInstanceState: Bundle?) {
dialog!!.setCanceledOnTouchOutside(false)
dialog?.setCanceledOnTouchOutside(false)
if (messageInt != 0) {
val message = getString(messageInt)
if (!TextUtils.isEmpty(message)) {
tv_loading_notice!!.text = message
tv_loading_notice?.text = message
}
}
tv_loading_cancel.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
Expand Down

0 comments on commit 8825ed5

Please sign in to comment.