Skip to content

Commit

Permalink
1. 开放 ReactiveFragment
Browse files Browse the repository at this point in the history
2. 补充 ReactiveFragment 的使用示例
  • Loading branch information
leavesCZY committed Apr 24, 2022
1 parent 28a9689 commit c4ef3ac
Show file tree
Hide file tree
Showing 34 changed files with 541 additions and 354 deletions.
16 changes: 7 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
}
signingConfigs {
releaseConfig {
storeFile file("..\\key.jks")
storeFile file(rootDir.absolutePath + File.separator + "key.jks")
storePassword "123456"
keyAlias "leavesCZY"
keyPassword "123456"
Expand Down Expand Up @@ -43,20 +43,18 @@ android {
}

dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.fragment:fragment-ktx:1.4.1"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'
debugImplementation 'com.github.leavesCZY.Monitor:monitor:1.1.5'
releaseImplementation 'com.github.leavesCZY.Monitor:monitor-no-op:1.1.5'
implementation project(path: ':reactivehttp')
Expand Down

This file was deleted.

12 changes: 9 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
android:supportsRtl="true"
android:theme="@style/ReactiveHttpAppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning"
tools:targetApi="m">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -26,18 +28,22 @@
</intent-filter>
</activity>
<activity
android:name=".ui.MapActivity"
android:name=".ui.weather.AreaActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.WeatherActivity"
android:name=".ui.weather.WeatherActivity"
android:exported="false"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".ui.SingleRequestActivity"
android:exported="false"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".ui.TogetherRequestActivity"
android:exported="false"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package github.leavesczy.reactivehttpsamples
import android.os.Bundle
import github.leavesczy.reactivehttpsamples.base.BaseActivity
import github.leavesczy.reactivehttpsamples.databinding.ActivityMainBinding
import github.leavesczy.reactivehttpsamples.ui.MapActivity
import github.leavesczy.reactivehttpsamples.ui.SingleRequestActivity
import github.leavesczy.reactivehttpsamples.ui.TogetherRequestActivity
import github.leavesczy.reactivehttpsamples.ui.weather.AreaActivity

/**
* @Author: leavesCZY
Expand All @@ -19,15 +19,15 @@ class MainActivity : BaseActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bind.btnWeather.setOnClickListener {
startActivity<MapActivity>()
}
bind.btnSingle.setOnClickListener {
startActivity<SingleRequestActivity>()
}
bind.btnTogether.setOnClickListener {
startActivity<TogetherRequestActivity>()
}
bind.btnWeather.setOnClickListener {
startActivity<AreaActivity>()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import github.leavesczy.reactivehttpsamples.core.mode.DistrictMode
* @Desc:
* @Github:https://github.com/leavesCZY
*/
class PlaceAdapter(
class AreaAdapter(
private val dataList: List<DistrictMode>,
private val onClickListener: OnClickListener
) :
RecyclerView.Adapter<PlaceAdapter.PlaceViewHolder>() {
RecyclerView.Adapter<AreaAdapter.PlaceViewHolder>() {

interface OnClickListener {
fun onClick(position: Int)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaceViewHolder {
return PlaceViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_place, parent, false)
LayoutInflater.from(parent.context).inflate(R.layout.item_area, parent, false)
)
}

Expand All @@ -35,13 +35,13 @@ class PlaceAdapter(
override fun onBindViewHolder(holder: PlaceViewHolder, position: Int) {
holder.tvPlaceName.text = dataList[position].name
holder.tvPlaceName.setOnClickListener {
onClickListener.onClick(holder.adapterPosition)
onClickListener.onClick(holder.bindingAdapterPosition)
}
}

class PlaceViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

var tvPlaceName: TextView = itemView.findViewById(R.id.tvPlaceName)
var tvPlaceName: TextView = itemView.findViewById(R.id.tvAreaName)

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package github.leavesczy.reactivehttpsamples.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -31,6 +32,7 @@ class WeatherAdapter(private val districtsModeList: List<CastsMode>) :
return districtsModeList.size
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: WeatherViewHolder, position: Int) {
val bean = districtsModeList[position]
holder.tvDate.text = bean.date
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package github.leavesczy.reactivehttpsamples.base

import github.leavesczy.reactivehttp.base.ReactiveFragment

/**
* @Author: leavesCZY
* @Date: 2022/4/23 20:38
* @Desc:
* @Github:https://github.com/leavesCZY
*/
open class BaseFragment : ReactiveFragment()
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class AppRemoteDataSource(iuiAction: IUIAction?) : RemoteExtendDataSource<ApiSer

private fun createOkHttpClient(): OkHttpClient {
val builder = OkHttpClient.Builder()
.readTimeout(1000L, TimeUnit.MILLISECONDS)
.writeTimeout(1000L, TimeUnit.MILLISECONDS)
.connectTimeout(1000L, TimeUnit.MILLISECONDS)
.readTimeout(10000L, TimeUnit.MILLISECONDS)
.writeTimeout(10000L, TimeUnit.MILLISECONDS)
.connectTimeout(10000L, TimeUnit.MILLISECONDS)
.retryOnConnectionFailure(true)
.addInterceptor(FilterInterceptor())
.addInterceptor(MonitorInterceptor(context = MainApplication.context))
Expand All @@ -41,7 +41,7 @@ class AppRemoteDataSource(iuiAction: IUIAction?) : RemoteExtendDataSource<ApiSer
}

/**
* 外部在这里来实现构建 Retrofit 的逻辑
* 在这里来实现构建 Retrofit 的逻辑
* @param baseHttpUrl
*/
override fun createRetrofit(baseHttpUrl: String): Retrofit {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package github.leavesczy.reactivehttpsamples.core.viewmodel.weather

import androidx.lifecycle.MutableLiveData
import github.leavesczy.reactivehttpsamples.base.BaseViewModel
import github.leavesczy.reactivehttpsamples.core.mode.DistrictMode
import kotlinx.coroutines.delay

/**
* @Author: leavesCZY
* @Date: 2022/4/23 21:07
* @Desc:
* @Github:https://github.com/leavesCZY
*/
class CityViewModel(private val province: String) : BaseViewModel() {

val cityLiveData = MutableLiveData<List<DistrictMode>>()

fun getCity() {
remoteDataSource.enqueueLoading({
//主动延迟一段时间,避免弹窗太快消失
delay(1200)
getCity(province)
}) {
onSuccess {
cityLiveData.value = it[0].districts
}
}
}

}
Loading

0 comments on commit c4ef3ac

Please sign in to comment.