Skip to content

Commit

Permalink
Support SDK 16
Browse files Browse the repository at this point in the history
  • Loading branch information
gzeinnumer committed Feb 15, 2021
1 parent 1a52a51 commit 8661ee5
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 2 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

239 changes: 237 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,237 @@
# BaseUtils

<p align="center">
<img src="https://github.com/gzeinnumer/BaseUtils/blob/master/preview/bg.jpg"/>
</p>

<h1 align="center">
BaseUtils
</h1>

<p align="center">
<a><img src="https://img.shields.io/badge/Version-1.0.0-brightgreen.svg?style=flat"></a>
<a><img src="https://img.shields.io/badge/ID-gzeinnumer-blue.svg?style=flat"></a>
<a><img src="https://img.shields.io/badge/Java-Suport-green?logo=java&style=flat"></a>
<a><img src="https://img.shields.io/badge/kotlin-Suport-green?logo=kotlin&style=flat"></a>
<a href="https://github.com/gzeinnumer"><img src="https://img.shields.io/github/followers/gzeinnumer?label=follow&style=social"></a>
<br>
<p>Simple function for <b>Date</b> and <b>String</b>.</p>
</p>

---
# Content List
* [Download](#download)
* [Feature List](#feature-list)
* [Tech stack and 3rd library](#tech-stack-and-3rd-library)
* [Usage](#usage)
* [Version](#version)
* [Contribution](#contribution)

---
# Download
Add maven `jitpack.io` and `dependencies` in `build.gradle (Project)` :
```gradle
// build.gradle project
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/module
dependencies {
...
implementation 'com.github.gzeinnumer:BaseUtils:version'
}
```

---
# Feature List
- [x] **Convert Time Format.** example from `2020-10-14` to `14-10-2020`. ([docs](#convert-time-format))
- [x] **Current Time.** with custom format. example `2020-10-14 16:50`. ([docs](#current-time-with-custom-format))
- [x] **Is Date In Range?.** to validate is your date in range or not. ([docs](#is-date-in-range))
- [x] **Calculate Date.** ([docs](#calculate-date))
- Add Year
- Add Month
- Add Week
- Add Day
- Add Hour
- Add Minutes
- [x] **Manipulation String**. ([docs](#manipulation-string))
- Remove Last Char
- Remove Last Char Custom Length
- Remove All Simbol
- Remove Spesific Simbol
- Remove First Char
- Remove First Char Custom Length
- Get Name From Url
- Remove Extension
- [x] **File To Base64**. ([docs](#file-to-base64))

---
# Tech stack and 3rd library
- SimpleDateFormat ([docs](https://developer.android.com/reference/java/text/SimpleDateFormat))

---
# Usage

### Convert Time Format.
> **Java**
```java
String value ="30-08-2020";

String oldFormat = "dd-MM-yyyy";
String newFormat = "yyyy-MM-dd";

String reformatOneString = MBUtilsDate.reformatDate(
value,
oldFormat,
newFormat,
Locale.getDefault()
);

Log.d(TAG, "onCreate: before "+value+" after "+reformatOneString); //2020-08-30
```
> **Kotlin**
```kotlin
var value = "30-08-2020"
Log.d(TAG, "onCreate: before : $value") //30-08-2020

val oldFormat = "dd-MM-yyyy"
val newFormat = "yyyy-MM-dd"

value = value.reformatDate(oldFormat,newFormat, Locale.getDefault())

Log.d(TAG, "onCreate: after : $value") //2020-08-30
```

#
### Current Time with custom format.
> **Java**
```java
String currentTime = MBUtilsDate.getCurrentTime("yyyy-MM-dd", Locale.getDefault());
Log.d(TAG, "onCreate: "+currentTime); //2020-10-14
```

#
### **Is Date In Range?.**
To check your date is in range between 2 date or not.
> **Java**
```java
//please make sure your date format are the same.

//with String
String toCheck = "07/10/2020";
String startDate ="04/10/2020";
String endDate = "08/10/2020";

boolean isInRange = MBUtilsDate.checkBetween(toCheck, startDate,endDate);

Log.d(TAG, "onCreate: "+isInRange); //true

//or `Date()`
try {
String formatDate = "dd/MM/yyyy";
SimpleDateFormat df = new SimpleDateFormat(formatDate);

Date toCheck = df.parse("07/10/2020");
Date startDate = df.parse("04/10/2020");
Date endDate = df.parse("08/10/2020");

boolean isInRange = MBUtilsDate.checkBetween(toCheck, startDate,endDate);

Log.d(TAG, "onCreate: "+isInRange); //true
} catch (ParseException e) {

}
```

#
### **Calculate Date.**
Add `date` and `time` with simple way.
> **Java**
```java
//please make sure time and pattern has same format
String time = "2014-01-11 10:10";
String pattern = "yyyy-MM-dd HH:mm";

CalculateDate calculateDate = new CalculateDate(time, pattern).addYear(2).addMonth(2);
calculateDate.addWeek(1);
calculateDate.addDay(2);
calculateDate.addHour(2);
calculateDate.addMinutes(2);

String result = calculateDate.getResult();
Log.d(TAG, "onCreate: "+result); //2016-03-20 12:12
```

#
### **Manipulation String.**
Make some modification to your `String` value to get value that you need.
> **Java**
```java
String str = "!!??!@Hello Zein";

//Remove Last Char
String result_1 = MBUtilsString.removeLastChar(str);
Log.d(TAG, "onCreate_1: "+ result_1); // !!??!@Hello Zei

//Remove Last Char Custom Length
String result_2 = MBUtilsString.removeLastCharCustomLength(str,3);
Log.d(TAG, "onCreate_2: "+ result_2); // !!??!@Hello Z

//Remove All Simbol
String result_3 = MBUtilsString.removeAllSimbol(str,"");
Log.d(TAG, "onCreate_3: "+ result_3); // HelloZein

//Remove Spesific Simbol
String result_4 = MBUtilsString.removeSpesificSimbol(str,"","!","?","@");
Log.d(TAG, "onCreate_4: "+ result_4); // Hello Zein

//Remove First Char
String result_5 = MBUtilsString.removeFirstChar(str);
Log.d(TAG, "onCreate_5: "+ result_5); // !??!@Hello Zein

//Remove First Char Custom Length
String result_6 = MBUtilsString.removeFirstCharCustomLength(str,3);
Log.d(TAG, "onCreate_6: "+ result_6); // ?!@Hello Zein

//Get Name From Url
String url = "https://asset-a.grid.id/crop/0x0:0x0/360x240/photo/2020/04/09/663219154.png";
String result_7 = MBUtilsString.getNameFromUrl(url);
Log.d(TAG, "onCreate_7: "+ result_7); // 663219154.png

//Remove Extension
String result_8 = MBUtilsString.removeExtension(result_7);
Log.d(TAG, "onCreate_8: "+ result_8); // 663219154
```

#
### **File To Base64.**
File Image From Path and convert to `Base64` with format `data:image/jpeg;base64,` + `....kagsfkajha`
> **Java**
```java
String filePath = "/storage/emulated/0/YourFolder/file_image.jpg";
val result_9 = MBBase64.convertToBase64FromPath(filePath);
Log.d(TAG, "onCreate_9: "+ result_8); // data:image/jpeg;base64,kasgfkaghaksfakgshalgal
```

---

## Version
- **0.3.0**
- First Release
- **0.4.0**
- convertToBase64FromPath
- **1.0.0**
- Support SDK 16

---

## Contribution
You can sent your constibution to `branch` `open-pull`.

---

```
Copyright 2020 M. Fadli Zein
```
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
}
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
Expand Down Expand Up @@ -36,4 +37,7 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
repositories {
mavenCentral()
}
1 change: 1 addition & 0 deletions bu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions bu/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10"
}
Empty file added bu/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions bu/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.gzeinnumer.bu;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.gzeinnumer.bu.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions bu/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gzeinnumer.bu">

</manifest>
4 changes: 4 additions & 0 deletions bu/src/main/java/com/gzeinnumer/bu/PlaceHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.gzeinnumer.bu;

public class PlaceHolder {
}
Loading

0 comments on commit 8661ee5

Please sign in to comment.