Skip to content

Commit b4c4436

Browse files
committed
baseFragment
1 parent af89052 commit b4c4436

16 files changed

+161
-55
lines changed

app/src/main/java/com/wingsofts/gankclient/router/GankClientUri.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ package com.wingsofts.gankclient.router
44
* Created by wing on 16-11-24.
55
*/
66
object GankClientUri {
7-
//关于页面
8-
const val ABOUT = "gank://androidwing.net/about/"
7+
//关于Activity
8+
const val ABOUT = "gank://androidwing.net/about/"
99
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.wingsofts.gankclient.router
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.net.Uri
6+
7+
/**
8+
* Created by wing on 16-11-24.
9+
*/
10+
object GankRouter{
11+
fun router(context: Context,url : String){
12+
val intent = Intent()
13+
intent.data = Uri.parse(url)
14+
intent.action = Intent.ACTION_VIEW
15+
context.startActivity(intent)
16+
}
17+
18+
}

app/src/main/java/com/wingsofts/gankclient/ui/BindingAdapter.kt renamed to app/src/main/java/com/wingsofts/gankclient/ui/DataBindingAdapterUtil.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@file:JvmName("BindingAdapter")
21

32
package com.wingsofts.gankclient.ui
43

@@ -9,7 +8,7 @@ import com.bumptech.glide.Glide
98
/**
109
* Created by wing on 11/24/16.
1110
*/
12-
object BindingAdapter {
11+
object DataBindingAdapterUtil {
1312

1413
@BindingAdapter("load_image")
1514
@JvmStatic

app/src/main/java/com/wingsofts/gankclient/ui/activity/MainActivity.kt

+6-24
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,18 @@ import com.wingsofts.gankclient.App
1212
import com.wingsofts.gankclient.R
1313
import com.wingsofts.gankclient.createApi
1414
import com.wingsofts.gankclient.router.GankClientUri
15-
import com.wingsofts.gankclient.ui.adapter.RandomAdapter
15+
import com.wingsofts.gankclient.router.GankRouter
16+
import com.wingsofts.gankclient.ui.adapter.FuckFoodAdapter
1617
import kotlinx.android.synthetic.main.activity_main.*
1718
import okhttp3.OkHttpClient
1819
import rx.android.schedulers.AndroidSchedulers
1920

2021
class MainActivity : AppCompatActivity() {
2122

22-
override fun onCreate(savedInstanceState: Bundle?) {
23-
super.onCreate(savedInstanceState)
24-
setContentView(R.layout.activity_main)
25-
btn_fuck.setOnClickListener {
26-
createApi().getData().observeOn(AndroidSchedulers.mainThread())
27-
.subscribe(
28-
{ res ->
29-
recyclerView.adapter = RandomAdapter(res.results)
30-
recyclerView.layoutManager = LinearLayoutManager(this)
31-
},
32-
{ e -> Log.e("wing", e.message) }
33-
)
34-
}
35-
36-
btn_about.setOnClickListener {
37-
38-
val intent = Intent()
39-
intent.data = Uri.parse(GankClientUri.ABOUT)
40-
intent.action = ACTION_VIEW
41-
startActivity(intent)
42-
}
23+
override fun onCreate(savedInstanceState: Bundle?) {
24+
super.onCreate(savedInstanceState)
25+
setContentView(R.layout.activity_main)
4326

4427

45-
46-
}
28+
}
4729
}

app/src/main/java/com/wingsofts/gankclient/ui/adapter/RandomAdapter.kt renamed to app/src/main/java/com/wingsofts/gankclient/ui/adapter/FuckFoodAdapter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.wingsofts.gankclient.databinding.ItemRandomBinding
1010
/**
1111
* Created by wing on 11/23/16.
1212
*/
13-
class RandomAdapter(private val mList: List<FuckFood>) : RecyclerView.Adapter<DataBoundViewHolder<ItemRandomBinding>>() {
13+
class FuckFoodAdapter(private val mList: List<FuckFood>) : RecyclerView.Adapter<DataBoundViewHolder<ItemRandomBinding>>() {
1414
override fun getItemCount(): Int {
1515
return mList.size
1616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.wingsofts.gankclient.ui.fragment
2+
3+
import android.databinding.DataBindingUtil
4+
import android.os.Bundle
5+
import android.view.LayoutInflater
6+
import android.view.ViewGroup
7+
import com.wingsofts.gankclient.R
8+
import com.wingsofts.gankclient.databinding.ViewRecyclerBinding
9+
import kotlinx.android.synthetic.main.view_recycler.*
10+
11+
/**
12+
*
13+
* Created by wing on 16-11-24.
14+
*/
15+
class AndroidFragment : BaseBingingFragment<ViewRecyclerBinding>() {
16+
17+
override fun createDataBinding(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): ViewRecyclerBinding {
18+
return ViewRecyclerBinding.inflate(inflater, container, false)
19+
}
20+
21+
override fun initView() {
22+
23+
}
24+
25+
companion object{
26+
fun newInstance():AndroidFragment{
27+
val fragment = AndroidFragment()
28+
val bundle = Bundle()
29+
fragment.arguments = bundle
30+
return fragment
31+
}
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.wingsofts.gankclient.ui.fragment
2+
3+
import android.app.Fragment
4+
import android.databinding.ViewDataBinding
5+
import android.os.Bundle
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
10+
/**
11+
* Created by wing on 16-11-24.
12+
*/
13+
abstract class BaseBingingFragment<B:ViewDataBinding> : Fragment(){
14+
private lateinit var mBinding : B
15+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View {
16+
mBinding = createDataBinding(inflater,container,savedInstanceState)
17+
initView()
18+
return mBinding.root
19+
20+
}
21+
22+
abstract fun createDataBinding(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): B
23+
24+
abstract fun initView()
25+
26+
}
3.95 KB
Loading
Loading
3.51 KB
Loading
4.24 KB
Loading

app/src/main/res/layout/activity_about.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
android:paddingRight="@dimen/activity_horizontal_margin"
1010
android:paddingTop="@dimen/activity_vertical_margin"
1111
tools:context="com.wingsofts.gankclient.ui.activity.AboutActivity">
12-
12+
<TextView
13+
android:layout_centerInParent="true"
14+
android:text="作者:wing"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content" />
1317
</RelativeLayout>
+25-25
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout>
3-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
android:id="@+id/activity_main"
6-
android:layout_width="match_parent"
7-
android:layout_height="match_parent"
8-
android:orientation="vertical"
9-
tools:context="com.wingsofts.gankclient.ui.activity.MainActivity">
2+
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
103

11-
<Button
12-
android:id="@+id/btn_fuck"
13-
android:layout_width="wrap_content"
14-
android:layout_height="wrap_content"
15-
android:text="手气不错" />
16-
<Button
17-
android:id="@+id/btn_about"
18-
android:text="关于"
19-
android:layout_width="wrap_content"
20-
android:layout_height="wrap_content" />
21-
22-
<android.support.v7.widget.RecyclerView
23-
android:background="#f1f1f1"
24-
android:id="@+id/recyclerView"
4+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:id="@+id/activity_main"
257
android:layout_width="match_parent"
268
android:layout_height="match_parent"
27-
>
9+
tools:context="com.wingsofts.gankclient.ui.activity.MainActivity">
10+
11+
<android.support.v4.view.ViewPager
12+
android:id="@+id/viewPager"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent">
15+
16+
</android.support.v4.view.ViewPager>
17+
<android.support.design.widget.BottomNavigationView
18+
android:id="@+id/navigationView"
19+
android:layout_gravity="bottom"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:background="@color/colorPrimary"
23+
app:itemIconTint="#fff"
24+
app:itemTextColor="#fff"
25+
app:menu="@menu/bottom"
26+
>
27+
28+
</android.support.design.widget.BottomNavigationView>
2829

29-
</android.support.v7.widget.RecyclerView>
30-
</LinearLayout>
30+
</android.support.design.widget.CoordinatorLayout>
3131
</layout>
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout>
3+
4+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:orientation="vertical">
8+
9+
<android.support.v7.widget.RecyclerView
10+
android:id="@+id/recyclerView"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent">
13+
14+
</android.support.v7.widget.RecyclerView>
15+
</LinearLayout>
16+
</layout>

app/src/main/res/menu/bottom.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:icon="@drawable/icon_android"
6+
android:enabled="true"
7+
app:showAsAction="ifRoom"
8+
android:title="Android"/>
9+
10+
<item
11+
android:icon="@drawable/icon_ios"
12+
android:enabled="true"
13+
app:showAsAction="ifRoom"
14+
android:title="iOS"/>
15+
<item
16+
android:icon="@drawable/icon_meizi"
17+
android:enabled="true"
18+
app:showAsAction="ifRoom"
19+
android:title="妹子"
20+
/>
21+
<item
22+
android:icon="@drawable/icon_about"
23+
android:enabled="true"
24+
app:showAsAction="ifRoom"
25+
android:title="关于"
26+
/>
27+
</menu>

0 commit comments

Comments
 (0)