Skip to content

Commit

Permalink
update libs
Browse files Browse the repository at this point in the history
digit separator added
  • Loading branch information
abbasalim committed Sep 15, 2022
1 parent bbfcf6c commit f1cf00f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ android {
dependencies {

// Compose Dependencies
implementation 'androidx.core:core-ktx:1.9.0-rc01'
implementation 'androidx.core:core-ktx:1.9.0'
implementation "androidx.compose.ui:ui:1.2.1"
implementation "androidx.compose.material:material:1.2.1"
implementation "androidx.compose.ui:ui-tooling-preview:1.2.1"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1'
implementation 'androidx.compose.material3:material3:1.0.0-beta01'
implementation 'androidx.compose.material3:material3:1.0.0-beta02'

// Splash Screen
implementation 'androidx.core:core-splashscreen:1.0.0'
Expand Down
6 changes: 3 additions & 3 deletions composeCalculator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ android {

dependencies {

implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation "androidx.compose.ui:ui:1.2.1"
implementation 'androidx.compose.material3:material3:1.0.0-beta01'
implementation 'androidx.compose.material3:material3:1.0.0-beta02'
implementation "androidx.compose.ui:ui-tooling-preview:1.2.1"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import ir.wave.composecalculator.Utils.*
import ir.wave.composecalculator.Utils.DigitSeprator.seRaghmBandi


@Composable
Expand All @@ -49,7 +50,7 @@ fun Calculator(

val viewModel = viewModel<CalculatorViewModel>()
viewModel.onResult = onResult
viewModel.roundResult=roundResult
viewModel.roundResult = roundResult
val onAction = viewModel::onAction
val state = viewModel.state
InitDefValue(defValue)
Expand Down Expand Up @@ -85,13 +86,14 @@ fun Calculator(
verticalArrangement = Arrangement.Bottom
) {
Text(
text = state.number1 + (state.operation?.symbol ?: "") + state.number2,
text = seRaghmBandi(state.number1) + (state.operation?.symbol
?: "") + seRaghmBandi(state.number2),
textAlign = TextAlign.End,
fontWeight = FontWeight.Light,
lineHeight = 50.sp,
fontSize = 50.sp,
maxLines = 3,
color = calculatorColors.mainTextColor
color = calculatorColors.mainTextColor,
)
}
Column(
Expand Down Expand Up @@ -360,7 +362,7 @@ fun Calculator(
private fun InitDefValue(
defValue: Double?
) {
if (defValue==null || defValue==0.0)return
if (defValue == null || defValue == 0.0) return
val viewModel = viewModel<CalculatorViewModel>()
val onAction = viewModel::onAction

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ir.wave.composecalculator.Utils;

public class DigitSeprator {


public static String seRaghmBandi(String Orgprice) {
return NRaghmBandi(Orgprice, true, 3);
}

//if after Number is Persian Text manfiInEnd must true
public static String seRaghmBandi(String Orgprice, boolean manfiInEnd) {
return NRaghmBandi(Orgprice, manfiInEnd, 3);
}

public static String NRaghmBandi(String Orgprice, boolean manfiInEnd, int nRaghami) {
String price;
String Ashar = "";
boolean cntManfi = false;
if (Orgprice.contains("-")) {
cntManfi = true;
Orgprice = Orgprice.replace("-", "");
}
if (Orgprice.contains(".")) {
price = Orgprice.substring(0, Orgprice.indexOf("."));
Ashar = Orgprice.substring(Orgprice.indexOf("."));
} else price = Orgprice;

StringBuilder s = new StringBuilder(price);
for (int i = s.length() - nRaghami; i > 0; i -= nRaghami) {
s.insert(i, ",");
}
if (cntManfi)
return manfiInEnd ? (s + Ashar + "-") : ("-" + s + Ashar);
else
return s + Ashar;
}

public static String AsharDasti(String mS) {
String f = mS;
if (mS.length() == 0 || !mS.contains(".") || (mS.contains(".") && mS.indexOf(".") == mS.length() - 1))
return mS;
else if (mS.length() - 1 - mS.indexOf(".") > 3)
f = mS.substring(0, mS.indexOf(".") + 4);
return f;
}

}

0 comments on commit f1cf00f

Please sign in to comment.