Creating classes that handle the jobject/class conversions.
This commit is contained in:
@@ -35,6 +35,7 @@ set (HEADERS
|
|||||||
types/RepeatTypes.h
|
types/RepeatTypes.h
|
||||||
types/ShuffleTypes.h
|
types/ShuffleTypes.h
|
||||||
utility/GeneralUtility.h
|
utility/GeneralUtility.h
|
||||||
|
utility/JNIObjectConversion.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ namespace model {
|
|||||||
public:
|
public:
|
||||||
Token() = default;
|
Token() = default;
|
||||||
Token(const std::string& accessToken) : accessToken(accessToken) { }
|
Token(const std::string& accessToken) : accessToken(accessToken) { }
|
||||||
Token(const std::string&& accessToken) :
|
Token(const std::string&& accessToken) : accessToken(accessToken) { }
|
||||||
accessToken(accessToken) { }
|
|
||||||
|
|
||||||
std::string accessToken;
|
std::string accessToken;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
//
|
||||||
|
// Created by brahmix on 1/13/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MEAR_JNIOBJECTCONVERSION_H
|
||||||
|
#define MEAR_JNIOBJECTCONVERSION_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "../model/Token.h"
|
||||||
|
#include "../model/User.h"
|
||||||
|
|
||||||
|
namespace utility {
|
||||||
|
template<typename Obj>
|
||||||
|
class JNIObjectConversion {
|
||||||
|
public:
|
||||||
|
// jobject to classes
|
||||||
|
template<typename Token, typename JE>
|
||||||
|
static Token ObjToToken(JE *env, Obj tokenObj) {
|
||||||
|
auto tokenClass = env->GetObjectClass(tokenObj);
|
||||||
|
|
||||||
|
auto accessTokenId = env->GetFieldId(tokenClass, "accessToken", "Ljava/lang/String;");
|
||||||
|
|
||||||
|
auto accessTokenVal = env->GetObjectField(tokenObj, accessTokenId);
|
||||||
|
|
||||||
|
Token token(std::move(env->GetStringUTFChars(accessTokenVal, nullptr)));
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// classes to jobject
|
||||||
|
template<typename Token, typename JE>
|
||||||
|
static Obj TokenToObj(JE *env, const Token& token) {
|
||||||
|
auto tokenClass = env->FindClass("com/example/mear/models/Token");
|
||||||
|
auto tokenConstructor = env->GetMethodID(tokenClass, "<init>", "()V");
|
||||||
|
auto tokenObj = env->NewObject(tokenClass, tokenConstructor);
|
||||||
|
|
||||||
|
auto accessTokenId = env->GetFieldID(tokenClass, "accessToken", "Ljava/lang/String;");
|
||||||
|
|
||||||
|
// TODO: left off here
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //MEAR_JNIOBJECTCONVERSION_H
|
||||||
@@ -5,7 +5,6 @@ import kotlinx.android.synthetic.main.content_login.*
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import org.jetbrains.anko.toast
|
import org.jetbrains.anko.toast
|
||||||
|
|
||||||
import com.example.mear.models.*
|
import com.example.mear.models.*
|
||||||
@@ -25,11 +24,6 @@ class LoginActivity : BaseServiceActivity() {
|
|||||||
login.setOnClickListener {
|
login.setOnClickListener {
|
||||||
loginButton()
|
loginButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
fab.setOnClickListener {view ->
|
|
||||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
|
||||||
.setAction("Action", null).show()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +34,7 @@ class LoginActivity : BaseServiceActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val saveCred = saveUserCred.isChecked
|
val saveCred = saveUserCred.isChecked
|
||||||
var apiInfo = APIInfo(apiUri.text.toString(), 1)
|
val apiInfo = APIInfo(apiUri.text.toString(), 1)
|
||||||
val usr = User(username.text.toString(), password.text.toString())
|
val usr = User(username.text.toString(), password.text.toString())
|
||||||
|
|
||||||
val usrRepo = UserRepository()
|
val usrRepo = UserRepository()
|
||||||
|
|||||||
@@ -20,14 +20,6 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/fab"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="@dimen/fab_margin"
|
|
||||||
app:srcCompat="@android:drawable/ic_dialog_email" />
|
|
||||||
|
|
||||||
<include layout="@layout/content_login" />
|
<include layout="@layout/content_login" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
@@ -8,17 +8,6 @@
|
|||||||
tools:context=".activities.LoginActivity"
|
tools:context=".activities.LoginActivity"
|
||||||
tools:showIn="@layout/activity_login">
|
tools:showIn="@layout/activity_login">
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/demoStream"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:text="Stream"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintVertical_bias="0.954" />
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/username"
|
android:id="@+id/username"
|
||||||
android:layout_width="245dp"
|
android:layout_width="245dp"
|
||||||
|
|||||||
Reference in New Issue
Block a user