mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
adding some main screen viewpager related files
This commit is contained in:
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
github: [tibbi]
|
||||
patreon: tiborkaputa
|
||||
custom: ["https://www.paypal.me/SimpleMobileTools", "https://www.simplemobiletools.com/donate"]
|
@ -0,0 +1,6 @@
|
||||
package com.simplemobiletools.dialer.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
|
||||
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet)
|
@ -0,0 +1,28 @@
|
||||
package com.simplemobiletools.dialer.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.simplemobiletools.commons.extensions.underlineText
|
||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.Config
|
||||
import com.simplemobiletools.dialer.models.Contact
|
||||
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
||||
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
||||
protected var activity: SimpleActivity? = null
|
||||
protected var allContacts = ArrayList<Contact>()
|
||||
|
||||
private var lastHashCode = 0
|
||||
private lateinit var config: Config
|
||||
|
||||
fun setupFragment(activity: SimpleActivity) {
|
||||
config = activity.config
|
||||
if (this.activity == null) {
|
||||
this.activity = activity
|
||||
|
||||
fragment_placeholder_2?.underlineText()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.simplemobiletools.dialer.models
|
||||
|
||||
import com.simplemobiletools.commons.extensions.normalizeString
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
|
||||
data class Contact(var id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String,
|
||||
var photoUri: String, var phoneNumbers: ArrayList<PhoneNumber>, var source: String, var starred: Int, var contactId: Int, var thumbnailUri: String,
|
||||
var organization: Organization) : Comparable<Contact> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
var startWithSurname = false
|
||||
}
|
||||
|
||||
override fun compareTo(other: Contact): Int {
|
||||
var firstString: String
|
||||
var secondString: String
|
||||
|
||||
when {
|
||||
sorting and SORT_BY_FIRST_NAME != 0 -> {
|
||||
firstString = firstName.normalizeString()
|
||||
secondString = other.firstName.normalizeString()
|
||||
}
|
||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> {
|
||||
firstString = middleName.normalizeString()
|
||||
secondString = other.middleName.normalizeString()
|
||||
}
|
||||
else -> {
|
||||
firstString = surname.normalizeString()
|
||||
secondString = other.surname.normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty()) {
|
||||
val fullCompany = getFullCompany()
|
||||
if (fullCompany.isNotEmpty()) {
|
||||
firstString = fullCompany.normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
if (secondString.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty()) {
|
||||
val otherFullCompany = other.getFullCompany()
|
||||
if (otherFullCompany.isNotEmpty()) {
|
||||
secondString = otherFullCompany.normalizeString()
|
||||
}
|
||||
}
|
||||
|
||||
var result = if (firstString.firstOrNull()?.isLetter() == true && secondString.firstOrNull()?.isLetter() == false) {
|
||||
-1
|
||||
} else if (firstString.firstOrNull()?.isLetter() == false && secondString.firstOrNull()?.isLetter() == true) {
|
||||
1
|
||||
} else {
|
||||
if (firstString.isEmpty() && secondString.isNotEmpty()) {
|
||||
1
|
||||
} else if (firstString.isNotEmpty() && secondString.isEmpty()) {
|
||||
-1
|
||||
} else {
|
||||
if (firstString.toLowerCase() == secondString.toLowerCase()) {
|
||||
getNameToDisplay().compareTo(other.getNameToDisplay(), true)
|
||||
} else {
|
||||
firstString.compareTo(secondString, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
result *= -1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun getNameToDisplay(): String {
|
||||
var firstPart = if (startWithSurname) surname else firstName
|
||||
if (middleName.isNotEmpty()) {
|
||||
firstPart += " $middleName"
|
||||
}
|
||||
|
||||
val lastPart = if (startWithSurname) firstName else surname
|
||||
val suffixComma = if (suffix.isEmpty()) "" else ", $suffix"
|
||||
val fullName = "$prefix $firstPart $lastPart$suffixComma".trim()
|
||||
return if (fullName.isEmpty() && organization.isNotEmpty()) {
|
||||
getFullCompany()
|
||||
} else {
|
||||
fullName
|
||||
}
|
||||
}
|
||||
|
||||
fun getFullCompany(): String {
|
||||
var fullOrganization = if (organization.company.isEmpty()) "" else "${organization.company}, "
|
||||
fullOrganization += organization.jobPosition
|
||||
return fullOrganization.trim().trimEnd(',')
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.simplemobiletools.dialer.models
|
||||
|
||||
data class Organization(var company: String, var jobPosition: String) {
|
||||
fun isEmpty() = company.isEmpty() && jobPosition.isEmpty()
|
||||
|
||||
fun isNotEmpty() = !isEmpty()
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package com.simplemobiletools.dialer.models
|
||||
|
||||
data class PhoneNumber(var value: String, var type: Int, var label: String, var normalizedNumber: String?)
|
@ -1,6 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/main_tabs_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
app:elevation="6dp"
|
||||
app:tabIndicatorColor="@android:color/white"
|
||||
app:tabIndicatorHeight="2dp"
|
||||
app:tabMinWidth="150dp"
|
||||
app:tabSelectedTextColor="@android:color/white" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyViewPager
|
||||
android:id="@+id/viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/main_tabs_holder" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
10
app/src/main/res/layout/fragment_contacts.xml
Normal file
10
app/src/main/res/layout/fragment_contacts.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.contacts.pro.fragments.ContactsFragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contacts_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/fragment_letters_layout"/>
|
||||
|
||||
</com.simplemobiletools.contacts.pro.fragments.ContactsFragment>
|
73
app/src/main/res/layout/fragment_letters_layout.xml
Normal file
73
app/src/main/res/layout/fragment_letters_layout.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/fragment_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/fragment_placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:alpha="0.8"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:text="@string/no_contacts_found"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:textStyle="italic"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/fragment_placeholder_2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/fragment_placeholder"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/change_filter"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/fragment_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
<com.reddit.indicatorfastscroll.FastScrollerView
|
||||
android:id="@+id/letter_fastscroller"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingTop="@dimen/big_margin"
|
||||
android:paddingBottom="@dimen/big_margin" />
|
||||
|
||||
<com.reddit.indicatorfastscroll.FastScrollerThumbView
|
||||
android:id="@+id/letter_fastscroller_thumb"
|
||||
android:layout_width="@dimen/fab_size"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@+id/letter_fastscroller"
|
||||
android:layout_alignBottom="@+id/letter_fastscroller"
|
||||
android:layout_marginEnd="@dimen/activity_margin"
|
||||
android:layout_toStartOf="@+id/letter_fastscroller" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||
android:id="@+id/fragment_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/activity_margin"
|
||||
android:src="@drawable/ic_plus_vector" />
|
||||
|
||||
</merge>
|
Reference in New Issue
Block a user