Skip to content

Commit

Permalink
OPPIA-1369, OPPIA-1387: Migrate adapter package to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoMoreta committed Sep 22, 2023
1 parent de6f5e5 commit 057753f
Show file tree
Hide file tree
Showing 57 changed files with 1,698 additions and 2,331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onCreate(Bundle savedInstanceState) {

final List<QuizAttempt> attempts = attemptsRepository.getQuizAttempts(this, stats);
QuizAttemptAdapter adapter = new QuizAttemptAdapter(this, attempts);
adapter.setOnItemClickListener((v, position) -> {
adapter.setOnItemClickListener((v, position, type, enabled) -> {
Intent i = new Intent(CourseQuizAttemptsActivity.this, QuizAttemptActivity.class);
Bundle tb = new Bundle();
QuizAttempt attempt = attempts.get(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ protected void onCreate(Bundle savedInstanceState) {
DevicesBTAdapter adapterPairedDevices = new DevicesBTAdapter(this, pairedDevicesNames);

// Find and set up the RecyclerView for paired devices
adapterPairedDevices.setOnItemClickListener((v, position) -> selectDevice(v));
adapterPairedDevices.setOnItemClickListener((v, position, type, enabled) -> selectDevice(v));
binding.recyclerPairedDevices.setAdapter(adapterPairedDevices);

// Find and set up the RecyclerView for newly discovered devices

newDevicesNames.clear();
adapterNewDevices = new DevicesBTAdapter(this, newDevicesNames);

adapterNewDevices.setOnItemClickListener((v, position) -> selectDevice(v));
adapterNewDevices.setOnItemClickListener((v, position, type, enabled) -> selectDevice(v));
binding.recyclerNewDevices.setAdapter(adapterNewDevices);

// Register for broadcasts when a device is discovered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void onDestroyActionMode(androidx.appcompat.view.ActionMode mode) {
}
});

coursesAdapter.setOnItemClickListener((view, position) -> {
coursesAdapter.setOnItemClickListener((view, position, type, enabled) -> {
Log.d("course-download", "Clicked " + position);
CourseInstallViewAdapter course = courses.get(position);
// When installing, don't do anything on click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onCreate(Bundle savedInstanceState) {
adapterResults = new SearchResultsAdapter(this, results);

binding.recyclerResultsSearch.setAdapter(adapterResults);
adapterResults.setOnItemClickListener((view, position) -> {
adapterResults.setOnItemClickListener((view, position, type, enabled) -> {
Course course = (Course) view.getTag(R.id.TAG_COURSE);
String digest = (String) view.getTag(R.id.TAG_ACTIVITY_DIGEST);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
adapterTags = new TagsAdapter(this, tags);

binding.recyclerTags.setAdapter(adapterTags);
adapterTags.setOnItemClickListener((view, position) -> {
adapterTags.setOnItemClickListener((view, position, type, enabled) -> {
Tag selectedTag = tags.get(position);
Intent i = new Intent(TagSelectActivity.this, DownloadActivity.class);
Bundle tb = new Bundle();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* This file is part of OppiaMobile - https://digital-campus.org/
*
* OppiaMobile is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OppiaMobile is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OppiaMobile. If not, see <http://www.gnu.org/licenses/>.
*/
package org.digitalcampus.oppia.adapter

import android.content.Context
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.view.LayoutInflater
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.google.android.material.tabs.TabLayout
import io.github.inflationx.calligraphy3.CalligraphyTypefaceSpan
import io.github.inflationx.calligraphy3.TypefaceUtils
import org.digitalcampus.mobile.learning.R

class ActivityPagerAdapter(
private val ctx: Context,
fm: FragmentManager,
private val fragments: List<Fragment>,
private val tabTitles: List<String>
) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {

companion object {
val TAG = ActivityPagerAdapter::class.simpleName
}

override fun getItem(index: Int): Fragment {
return fragments[index]
}

override fun getPageTitle(position: Int): CharSequence {
val title = tabTitles[position]
val typefaceSpan = CalligraphyTypefaceSpan(TypefaceUtils.load(ctx.assets, "fonts/montserrat.ttf"))
val s = SpannableStringBuilder()
s.append(title).setSpan(typefaceSpan, 0, title.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
return SpannableString.valueOf(s)
}

override fun getCount(): Int {
return fragments.size
}

private fun updateTabLayout(tab: TabLayout.Tab?, layoutId: Int, tabTitle: String?) {
tab?.let {
val v = LayoutInflater.from(ctx).inflate(layoutId, null)
val tv = v.findViewById<TextView>(R.id.tabTitle)
tv.text = tabTitle
tab.customView = v
}
}

fun updateTabViews(tabs: TabLayout) {
if (tabs.tabCount == 1) {
updateTabLayout(tabs.getTabAt(0), R.layout.tablayout_fullwidth_tab, tabTitles[0])
return
}
for (i in 0 until tabs.tabCount) {
updateTabLayout(tabs.getTabAt(i), R.layout.tablayout_fixed_tab, tabTitles[i])
}
}
}

This file was deleted.

Loading

0 comments on commit 057753f

Please sign in to comment.