-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: pie chart for installer packages
- Loading branch information
Showing
19 changed files
with
493 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/main/java/app/simple/inure/adapters/analytics/AdapterInstallerLegend.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package app.simple.inure.adapters.analytics | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.res.ColorStateList | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import app.simple.inure.R | ||
import app.simple.inure.constants.InstallerColors | ||
import app.simple.inure.decorations.corners.DynamicCornerAccentColor | ||
import app.simple.inure.decorations.ripple.DynamicRippleLegendLinearLayout | ||
import app.simple.inure.decorations.typeface.TypeFaceTextView | ||
import app.simple.inure.util.ColorUtils | ||
import app.simple.inure.util.NullSafety.isNotNull | ||
import com.github.mikephil.charting.data.PieEntry | ||
|
||
class AdapterInstallerLegend(private val pieEntries: ArrayList<PieEntry>, | ||
private val colors: ArrayList<Int>, | ||
val labels: HashMap<String, String>, | ||
private val function: ((PieEntry, Boolean) -> Unit)? = null) : RecyclerView.Adapter<AdapterInstallerLegend.Holder>() { | ||
|
||
private var highLightedEntry: PieEntry? = null | ||
private var lastHighlightedEntry: PieEntry? = null | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { | ||
return Holder(LayoutInflater.from(parent.context) | ||
.inflate(R.layout.adapter_legend, parent, false)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: Holder, position: Int) { | ||
val color = InstallerColors.getInstallerColorMap().get(pieEntries[position].label) ?: colors[position] | ||
holder.color.backgroundTintList = ColorStateList.valueOf(color) | ||
holder.label.text = labels[pieEntries[position].label] | ||
|
||
holder.container.setOnClickListener { | ||
function?.invoke(pieEntries[position], false) | ||
} | ||
|
||
holder.container.setOnLongClickListener { | ||
function?.invoke(pieEntries[position], true) | ||
true | ||
} | ||
|
||
if (highLightedEntry != null && highLightedEntry!!.label == pieEntries[position].label) { | ||
holder.container.highlight(ColorUtils.lightenColor(color, 0.2F)) | ||
} else { | ||
holder.container.setRippleColor(ColorUtils.lightenColor(color, 0.2F)) | ||
holder.container.unHighlight() | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return pieEntries.size | ||
} | ||
|
||
@SuppressLint("NotifyDataSetChanged") | ||
fun highlightEntry(e: PieEntry?) { | ||
highLightedEntry = e | ||
if (e.isNotNull()) { | ||
for (i in pieEntries.indices) { | ||
if (pieEntries[i].label == e?.label) { | ||
lastHighlightedEntry = e | ||
notifyItemChanged(i) | ||
break | ||
} | ||
} | ||
} else { | ||
for (i in pieEntries.indices) { | ||
if (pieEntries[i].label == lastHighlightedEntry?.label) { | ||
lastHighlightedEntry = null | ||
notifyItemChanged(i) | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
inner class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
val color: DynamicCornerAccentColor = itemView.findViewById(R.id.legend_color) | ||
val label: TypeFaceTextView = itemView.findViewById(R.id.legend_text) | ||
val container: DynamicRippleLegendLinearLayout = itemView.findViewById(R.id.container) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/java/app/simple/inure/constants/InstallerColors.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app.simple.inure.constants | ||
|
||
object InstallerColors { | ||
|
||
const val UNKNOWN = 0xFF6D7291.toInt() | ||
|
||
private val colors: ArrayList<Int> by lazy { | ||
arrayListOf( | ||
0xFFEA4335.toInt(), // Play Store | ||
0xFFFFB401.toInt(), // Aurora Store | ||
0xFF217AD3.toInt(), // F-Droid | ||
0xFFFFA967.toInt(), // Inure | ||
0xFF4CAF50.toInt(), // APKMirror | ||
0xFF9E9E9E.toInt(), // System | ||
0xFF673AB7.toInt(), // Aptoide | ||
0xFF00C4F7.toInt(), // Amazon Appstore | ||
0xFF2196F3.toInt(), // APKPure | ||
0xFF3F51B5.toInt(), // Samsung Galaxy Store | ||
0xFFF65C5B.toInt(), // Huawei AppGallery | ||
0xFFE91E63.toInt(), // SlideME | ||
) | ||
} | ||
|
||
private val colorMap = mapOf( | ||
"com.android.vending" to 0xFFEA4335.toInt(), | ||
"com.google.android.packageinstaller" to 0xFFEA4335.toInt(), | ||
"com.aurora.store" to 0xFFFFB401.toInt(), | ||
"org.fdroid.fdroid" to 0xFF217AD3.toInt(), | ||
"app.simple.inure" to 0xFFFFA967.toInt(), | ||
"com.apkmirror" to 0xFF4CAF50.toInt(), | ||
"system" to 0xFF9E9E9E.toInt(), | ||
"com.android.shell" to 0xFF9E9E9E.toInt(), | ||
"com.aptoide.pt" to 0xFF673AB7.toInt(), | ||
"com.amazon.venezia" to 0xFF00C4F7.toInt(), | ||
"com.apkpure.aegon" to 0xFF2196F3.toInt(), | ||
"com.sec.android.app.samsungapps" to 0xFF3F51B5.toInt(), | ||
"com.huawei.appmarket" to 0xFFF65C5B.toInt(), | ||
"com.slideme.sam.manager" to 0xFFE91E63.toInt(), | ||
"com.xiaomi.market" to 0xFFE173E5.toInt(), | ||
"com.xiaomi.discover" to 0xFF3B56E5.toInt(), | ||
) | ||
|
||
fun getInstallerColors(): ArrayList<Int> { | ||
return colors | ||
} | ||
|
||
fun getInstallerColorMap(): Map<String, Int> { | ||
return colorMap | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,7 @@ | ||
package app.simple.inure.models; | ||
|
||
public class Triple <T, U, V> { | ||
private final T first; | ||
private final U second; | ||
private final V third; | ||
|
||
public Triple(T first, U second, V third) { | ||
this.first = first; | ||
this.second = second; | ||
this.third = third; | ||
} | ||
|
||
public T getFirst() { | ||
return first; | ||
} | ||
|
||
public U getSecond() { | ||
return second; | ||
} | ||
|
||
public V getThird() { | ||
return third; | ||
} | ||
public record Triple <T, U, V>( | ||
T first, | ||
U second, | ||
V third) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.