Skip to content

Commit

Permalink
20180824
Browse files Browse the repository at this point in the history
  • Loading branch information
zyhSDU committed Aug 24, 2018
1 parent e3901b3 commit 970eac3
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 68 deletions.
7 changes: 7 additions & 0 deletions .idea/dictionaries/Administrator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ac.MainActivity"
android:name=".ac.ac.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme">
Expand All @@ -24,9 +24,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ac.SplashActivity" />
<activity android:name=".ac.LoginAc" />
<activity android:name=".ac.RegisterAc" />
<activity android:name=".ac.abac.SplashAbAc" />
<activity android:name=".ac.abac.LoginAbAc" />
<activity android:name=".ac.abac.RegisterAbAc" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.administrator.smartschool.ac
package com.example.administrator.smartschool.ac.abac

/**
* Created by Administrator on 2018/3/23 0023.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.administrator.smartschool.ac;
package com.example.administrator.smartschool.ac.abac;

import com.example.administrator.smartschool.R;

/**
* Created by Administrator on 2018/7/18 0018.
*/

public class LoginAc extends BaseAbAc{
public class LoginAbAc extends BaseAbAc{
@Override
public int getLayoutResId() {
return R.layout.ac_login;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.administrator.smartschool.ac;
package com.example.administrator.smartschool.ac.abac;

import com.example.administrator.smartschool.R;

/**
* Created by Administrator on 2018/7/18 0018.
*/

public class RegisterAc extends BaseAbAc{
public class RegisterAbAc extends BaseAbAc{
@Override
public int getLayoutResId() {
return R.layout.ac_register;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.example.administrator.smartschool.ac
package com.example.administrator.smartschool.ac.abac

import android.content.Intent
import android.os.Handler
import android.view.MotionEvent
import com.example.administrator.smartschool.R
import com.example.administrator.smartschool.ac.ac.MainActivity

class SplashActivity : BaseAbAc() {
class SplashAbAc : BaseAbAc() {
private val handler = Handler()

override val layoutResId: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.administrator.smartschool.ac
package com.example.administrator.smartschool.ac.ac

import android.os.Bundle
import android.support.design.widget.Snackbar
Expand All @@ -9,7 +9,10 @@ import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import com.example.administrator.smartschool.R
import com.example.administrator.smartschool.adapter.FragmentPagerAdapter0
import com.example.administrator.smartschool.adapter.BaseFragmentPagerAdapter
import com.example.administrator.smartschool.fragment_v4.BottomFragment1
import com.example.administrator.smartschool.fragment_v4.BottomFragment2
import com.example.administrator.smartschool.fragment_v4.BottomFragment3
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import kotlinx.android.synthetic.main.content_main.*
Expand All @@ -36,7 +39,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}

private fun setBottomNavigationView() {
ViewPager_main.adapter = FragmentPagerAdapter0(supportFragmentManager)
ViewPager_main.adapter = object : BaseFragmentPagerAdapter(supportFragmentManager){
init {
fragmentList= arrayListOf(BottomFragment1(), BottomFragment2(), BottomFragment3())
}
}
bottomNavigationView_main.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.item_0_menu_bottom_main -> ViewPager_main.currentItem = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import com.example.administrator.smartschool.fragment_v4.BaseFragment
* Created by zhangYuHan on 2017/8/17.
*/

/**
* 使用例子
// ViewPager_main.adapter = object : BaseFragmentPagerAdapter(supportFragmentManager){
// init {
// fragmentList= arrayListOf(BottomFragment1(), BottomFragment2(), BottomFragment3())
// }
// }
*/
abstract class BaseFragmentPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
protected lateinit var fragmentList: ArrayList<BaseFragment>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,9 @@ class BaseLVAdapter(private val context: Context, private val list: List<AbMenuI
return position.toLong()
}

//由于我们的ListView中的Item显示的方式都非常的简单,因此ViewHolder类中也就仅仅定义了一个TextView属性...
override fun getView(position: Int, convertView: View?, viewGroup: ViewGroup): View {
var convertView = convertView
val holder: ViewHolder
/*这个判断其实是为了复用而定义的...因为ListView都是动态进行加载的..
如果ListView中的Item超过了屏幕的大小,那么势必就需要进行下拉...
下拉就代表原来的那些ListView就需要被销毁...
那么总不能每一次滑动我们都新建立一个ViewHolder对象..我们可以把这些被销毁的ViewHolder进行复用...
有了复用之后,再次滑动的时候ViewHolder会自动调用那些被销毁掉的进行复用...从而使得资源得到重新加载...
说白了就是提高了复用性...
*/
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(itemResource, null) //定义一个视图对象View...
holder = ViewHolder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,20 @@ import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlin.collections.ArrayList

/**
* Created by Administrator on 2018/5/31 0031.
*/
abstract class BaseRVAdapter(
protected val context: Context,
protected val arrOfData: List<Any>
) : RecyclerView.Adapter<BaseRVAdapter.MyViewHolder>() {
protected abstract val layoutId: Int
protected abstract val arrOfResId:ArrayList<Int>

abstract class BaseRVAdapter(val context: Context, val datum: List<Any>) : RecyclerView.Adapter<BaseRVAdapter.MyViewHolder>(), LayoutAndViews {
override fun getItemCount(): Int {
return arrOfData.size
return datum.size
}

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(context).inflate(layoutId, parent, false))
}

inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val arrOfView = arrayOfNulls<View>(arrOfResId.size)

init {
arrOfResId.indices.forEach { i -> arrOfView[i] = itemView.findViewById(arrOfResId[i]) }
}
val views = Array<View>(viewsId.size, { i -> itemView.findViewById(viewsId[i]) })
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.administrator.smartschool.adapter


interface LayoutAndViews {
val layoutId: Int
val viewsId: ArrayList<Int>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class RVAdapter0(context: Context, arrayList: List<Any>) : BaseRVAdapter(context
override val layoutId: Int
get() = R.layout.item0

override val arrOfResId: ArrayList<Int>
override val viewsId: ArrayList<Int>
get() = arrayListOf(R.id.btn_item_view)

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val bean0 = arrOfData[position] as Bean0
val button = holder.arrOfView[0] as Button
val bean0 = datum[position] as Bean0
val button = holder.views[0] as Button
button.text = bean0.str

button.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Context
import android.widget.TextView
import com.ab.global.AbMenuItem
import com.example.administrator.smartschool.R
import java.util.ArrayList
import kotlin.collections.ArrayList

/**
* Created by Administrator on 2018/6/1 0001.
Expand All @@ -14,12 +14,12 @@ class RVAdapter1(context: Context, arrayList: List<Any>) : BaseRVAdapter(context
override val layoutId: Int
get() = R.layout.list_pop_item

override val arrOfResId: ArrayList<Int>
override val viewsId: ArrayList<Int>
get() = arrayListOf(R.id.pop_item)

override fun onBindViewHolder(holder: BaseRVAdapter.MyViewHolder, position: Int) {
val abMenuItem = arrOfData[position] as AbMenuItem
val textView = holder.arrOfView[0] as TextView
val abMenuItem = datum[position] as AbMenuItem
val textView = holder.views[0] as TextView
textView.text = abMenuItem.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class RVAdapter2(context: Context, arrayList: List<Any>) : BaseRVAdapter(context
override val layoutId: Int
get() = R.layout.list_pop_item2

override val arrOfResId: ArrayList<Int>
override val viewsId: ArrayList<Int>
get() = arrayListOf(R.id.pop_item2)

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val abMenuItem = arrOfData[position] as AbMenuItem
val textView = holder.arrOfView[0] as TextView
val abMenuItem = datum[position] as AbMenuItem
val textView = holder.views[0] as TextView
textView.text = abMenuItem.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class RVAdapter3(context: Context, list: List<Any>) : BaseRVAdapter(context, lis
override val layoutId: Int
get() = R.layout.item_rv_3

override val arrOfResId: ArrayList<Int>
override val viewsId: ArrayList<Int>
get() = arrayListOf(R.id.tv_item_rv_3)

override fun onBindViewHolder(holder: BaseRVAdapter.MyViewHolder, position: Int) {
val clazz = arrOfData[position] as Class<*>
val view = holder.arrOfView[0] as TextView
val clazz = datum[position] as Class<*>
val view = holder.views[0] as TextView
view.text = clazz.simpleName
view.setOnClickListener {
context.startActivity(Intent(context, clazz))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/app_bar_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.smartschool.ac.MainActivity">
tools:context="com.example.administrator.smartschool.ac.ac.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.administrator.smartschool.ac.MainActivity"
tools:context="com.example.administrator.smartschool.ac.ac.MainActivity"
tools:showIn="@layout/app_bar_main">
<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 970eac3

Please sign in to comment.