use ListView for library fragment
This commit is contained in:
		| @ -4,16 +4,11 @@ import android.os.Bundle | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import android.widget.ArrayAdapter | ||||
| import androidx.fragment.app.Fragment | ||||
| import kotlinx.android.synthetic.main.fragment_library.* | ||||
| import kotlinx.coroutines.Dispatchers | ||||
| import kotlinx.coroutines.GlobalScope | ||||
| import kotlinx.coroutines.launch | ||||
| import kotlinx.coroutines.withContext | ||||
| import kotlinx.coroutines.* | ||||
| import org.mosad.teapod.R | ||||
| import org.mosad.teapod.parser.AoDParser | ||||
| import org.mosad.teapod.ui.components.MediaLinearLayout | ||||
| import org.mosad.teapod.util.CustomAdapter | ||||
| import org.mosad.teapod.util.GUIMedia | ||||
|  | ||||
| @ -23,35 +18,27 @@ class LibraryFragment : Fragment() { | ||||
|     private lateinit var adapter : CustomAdapter | ||||
|  | ||||
|     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||||
|         val root =  inflater.inflate(R.layout.fragment_library, container, false) | ||||
|         return root | ||||
|         return inflater.inflate(R.layout.fragment_library, container, false) | ||||
|     } | ||||
|  | ||||
|     override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||
|         super.onViewCreated(view, savedInstanceState) | ||||
|  | ||||
|  | ||||
|         adapter = CustomAdapter(requireContext(),layoutInflater, mediaList)//ArrayAdapter(requireContext(), R.layout.linear_media, R.id.text_title, mediaList) | ||||
|         GlobalScope.launch { | ||||
|             val parser = AoDParser() | ||||
|             mediaList = parser.listAnime() | ||||
|  | ||||
|         list_library.adapter = adapter | ||||
|             println("setting adapter") | ||||
|             withContext(Dispatchers.Main) { | ||||
|                 adapter = CustomAdapter(requireContext(), mediaList)//ArrayAdapter(requireContext(), R.layout.linear_media, R.id.text_title, mediaList) | ||||
|  | ||||
|         text_dashboard.text = "Loading Animes ..." | ||||
|                 list_library.adapter = adapter | ||||
|                 adapter.notifyDataSetChanged() | ||||
|             } | ||||
|  | ||||
|         loadAnimeList() | ||||
|     } | ||||
|  | ||||
|     private fun loadAnimeList() = GlobalScope.launch { | ||||
|  | ||||
|         val parser = AoDParser() | ||||
|         mediaList = parser.listAnime() | ||||
|  | ||||
|         text_dashboard.text = "got ${mediaList.size} animes" | ||||
|  | ||||
|         withContext(Dispatchers.Main) { | ||||
|             adapter.notifyDataSetChanged() | ||||
|             println("notifiyed") | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -1,13 +0,0 @@ | ||||
| package org.mosad.teapod.ui.library | ||||
|  | ||||
| import androidx.lifecycle.LiveData | ||||
| import androidx.lifecycle.MutableLiveData | ||||
| import androidx.lifecycle.ViewModel | ||||
|  | ||||
| class LibraryViewModel : ViewModel() { | ||||
|  | ||||
|     private val _text = MutableLiveData<String>().apply { | ||||
|         value = "This is the library Fragment" | ||||
|     } | ||||
|     val text: LiveData<String> = _text | ||||
| } | ||||
| @ -9,14 +9,13 @@ import android.widget.ImageView | ||||
| import android.widget.TextView | ||||
| import com.bumptech.glide.Glide | ||||
| import org.mosad.teapod.R | ||||
| import org.mosad.teapod.ui.components.MediaLinearLayout | ||||
|  | ||||
| class CustomAdapter(context: Context, private val layoutInflater: LayoutInflater, private val media: ArrayList<GUIMedia>) : ArrayAdapter<GUIMedia>(context, R.layout.linear_media) { | ||||
| class CustomAdapter(context: Context, private val media: ArrayList<GUIMedia>) : ArrayAdapter<GUIMedia>(context, R.layout.linear_media, media) { | ||||
|  | ||||
|     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||||
|         println("view") | ||||
|  | ||||
|         return if (convertView == null) { | ||||
|             val guiMedia = layoutInflater.inflate(R.layout.linear_media, null) | ||||
|             val guiMedia = LayoutInflater.from(context).inflate(R.layout.linear_media, parent, false) | ||||
|  | ||||
|             val textTitle = guiMedia.findViewById<TextView>(R.id.text_title) | ||||
|             val imagePoster = guiMedia.findViewById<ImageView>(R.id.image_poster) | ||||
|  | ||||
| @ -15,28 +15,4 @@ | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|     <ScrollView | ||||
|         android:id="@+id/scroll_library" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         android:visibility="gone"> | ||||
|  | ||||
|         <LinearLayout | ||||
|             android:id="@+id/linear_library" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:orientation="vertical"> | ||||
|  | ||||
|             <TextView | ||||
|                 android:id="@+id/text_dashboard" | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:layout_marginStart="8dp" | ||||
|                 android:layout_marginTop="8dp" | ||||
|                 android:layout_marginEnd="8dp" | ||||
|                 android:textAlignment="center" | ||||
|                 android:textSize="20sp" /> | ||||
|         </LinearLayout> | ||||
|     </ScrollView> | ||||
|  | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
		Reference in New Issue
	
	Block a user