Skip to content

Commit

Permalink
نمایش ساب دیفالت
Browse files Browse the repository at this point in the history
به روزرسانی ساب هر یک ساعت
  • Loading branch information
hiddify-com committed May 3, 2023
1 parent 580935d commit bfcec01
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions V2rayNG/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
minSdkVersion 21
targetSdkVersion Integer.parseInt("$targetSdkVer")
multiDexEnabled true
versionCode 5100500 //hiddify
versionName "1.5.0" //hiddify
versionCode 5100520 //hiddify when comes to version 5 change it
versionName "2.0.0" //hiddify
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ data class SubscriptionItem(
var lastUpdateTime: Long = System.currentTimeMillis(),
var used: Long=-1,
var total: Long=-1,
var expire: Long=-1,
var expire: Long=-1,//in ms
var home_link: String="",
var update_interval: Int=6
var update_interval: Int=1
) {

fun needUpdate(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class HiddifyMainActivity : BaseActivity(), /*NavigationView.OnNavigationItemSel
}
binding.show.showGone(!subscription.second.home_link.isNullOrEmpty())


binding.profileName.click {
bottomSheetPresenter.show(
supportFragmentManager,
Expand All @@ -225,6 +226,7 @@ class HiddifyMainActivity : BaseActivity(), /*NavigationView.OnNavigationItemSel
binding.updateSubscription.click {
importConfigViaSub(HiddifyUtils.getSelectedSubId())
}
binding.updateSubscription.showGone(subscription.second.url.startsWith("http"))
binding.profileBox.show()
} ?: also {
binding.profileBox.gone()
Expand Down Expand Up @@ -536,6 +538,8 @@ class HiddifyMainActivity : BaseActivity(), /*NavigationView.OnNavigationItemSel
count = AngConfigManager.importBatchConfig(Utils.decode(server!!), subid2, append, selectSub = selectSub)
}
if (count > 0) {
if(selectSub)
HiddifyUtils.setMode(connect_mode)
hiddifyToast(R.string.toast_success)
hiddifyMainViewModel.reloadServerList()
hiddifyMainViewModel.reloadSubscriptionsState()
Expand Down
28 changes: 12 additions & 16 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/HiddifyUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ class HiddifyUtils {
if (time < 0)
return "".bold("")

val now = System.currentTimeMillis() / 1000
val diffInMillis = (time - now) / 86400
val now = System.currentTimeMillis()
val diffInMillis = (time - now)/86400/1000
if (diffInMillis <= 0)
return if (getLocale(context) == Locale("fa") || getLocale(context).toString() == "fa_IR")
"منقضی شده".bold("")
else "Expired".bold("")
return context.getString(R.string.expired) .bold("")

if (totalInBytes>0 && totalInBytes <= usedInBytes)
return context.getString(R.string.full_usage) .bold("")

if (totalInBytes == usedInBytes)
return if (getLocale(context) == Locale("fa") || getLocale(context).toString() == "fa_IR")
"اتمام حجم".bold("")
else "Completion of the volume".bold("")


return if (getLocale(context) == Locale("fa") || getLocale(context).toString() == "fa_IR") {
Expand Down Expand Up @@ -113,16 +110,15 @@ class HiddifyUtils {
}

fun checkState(time: Long, totalInBytes: Long, usedInBytes: Long): String {
if (time < 0)
if (totalInBytes>0 && usedInBytes>=totalInBytes)
return "disable"


val now = System.currentTimeMillis() / 1000
val diffInMillis = (time - now) / 86400
if (diffInMillis <= 0)
if (time>0 && diffInMillis <= 0)
return "disable"

if (totalInBytes == usedInBytes)
return "disable"

return "enable"
}
Expand Down Expand Up @@ -175,9 +171,9 @@ class HiddifyUtils {
get("download=([0-9]+)")?.apply {
sub.used += toLong()
}
sub.total = get("total=([0-9]+)")?.toLong() ?: 0

sub.expire = get("expire=([0-9]+)")?.toLong() ?: 0
sub.total = get("total=([0-9]+)")?.toLong() ?: -1
//in ms
sub.expire = get("expire=([0-9]+)")?.toLong()?.times(1000) ?: -1
}

subStorage?.encode(subid, Gson().toJson(sub))
Expand Down
6 changes: 3 additions & 3 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/MmkvManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ object MmkvManager {
}

fun decodeSubscriptions(): List<Pair<String, SubscriptionItem>> {
val subscriptions = mutableListOf<Pair<String, SubscriptionItem>>()
var subscriptions = mutableListOf<Pair<String, SubscriptionItem>>()
subStorage?.allKeys()?.forEach { key ->
val json = subStorage?.decodeString(key)
if (!json.isNullOrBlank()) {
subscriptions.add(Pair(key, Gson().fromJson(json, SubscriptionItem::class.java)))
}
}
subscriptions.sortedBy { (guid, value) -> if (guid=="default") Long.MAX_VALUE else value.addedTime }
return subscriptions
return subscriptions.sortedBy { (guid, value) -> if (guid=="default") Long.MIN_VALUE else -value.addedTime }

}


Expand Down
1 change: 1 addition & 0 deletions V2rayNG/app/src/main/res/values-fa/hiddify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
<string name="add_profile">افزودن پروفایل</string>
<string name="title_sub_update_failed" >به روزرسانی اشتراک با خطا مواجه شد</string>
<string name="no_server_selected">هیچ سروری انتخاب نشده است.</string>
<string name="expired">منقضی شده</string>
</resources>
1 change: 1 addition & 0 deletions V2rayNG/app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<string name="connection_test_error_status_code">کد خطا: #%d</string>
<string name="connection_connected">متصل شد. کلیک برای بررسی اتصال</string>
<string name="connection_not_connected">متصل نیست</string>
<string name="full_usage">اتمام حجم</string>

<string-array name="share_method">
<item>QRcode</item>
Expand Down
1 change: 1 addition & 0 deletions V2rayNG/app/src/main/res/values/hiddify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
<string name="add_profile">Add Profile</string>
<string name="title_sub_update_failed" translatable="false">Update Sub failed</string>
<string name="no_server_selected">No server is selected!</string>
<string name="expired">Expired</string>
</resources>
1 change: 1 addition & 0 deletions V2rayNG/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<string name="connection_test_error_status_code">Error code: #%d</string>
<string name="connection_connected">Connected, tap to check connection</string>
<string name="connection_not_connected">Not connected</string>
<string name="full_usage">Package Finished</string>

<string-array name="share_method">
<item>QRcode</item>
Expand Down

0 comments on commit bfcec01

Please sign in to comment.