Skip to content

Commit

Permalink
feat: Added LicenseActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Feb 6, 2024
1 parent 9e9339a commit 73967f7
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nuxt.isNuxtApp": false
}
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ android {
namespace 'com.block.web.builder'
compileSdk 34
buildToolsVersion "34.0.0"

def getCommitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
Expand Down Expand Up @@ -156,12 +156,12 @@ dependencies {
implementation platform("$editorGroupId:bom:0.22.0")
implementation "$editorGroupId:editor"
implementation "$editorGroupId:language-textmate"

implementation 'org.nanohttpd:nanohttpd:2.3.0'

implementation platform('com.google.firebase:firebase-bom:32.3.1')
implementation 'com.google.firebase:firebase-analytics'

implementation project(path:':common')
implementation project(path:':editor')
implementation project(path:':block:core')
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,11 @@
<activity
android:name="com.block.web.builder.ui.activities.SettingActivity"
android:exported="true" />
<activity
android:name="com.block.web.builder.ui.activities.LicenseActivity"
android:exported="true" />
<activity
android:name="com.block.web.builder.ui.activities.LicenseReaderActivity"
android:exported="true" />
</application>
</manifest>
6 changes: 6 additions & 0 deletions app/src/main/assets/LicenseList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"Name": "Free Sound - Sound Attribution",
"Path": "attribution/free_sound_attribution.json"
}
]
3 changes: 3 additions & 0 deletions app/src/main/assets/attribution/free_sound_attribution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
S: Keyboard Key by AntoineRomo | License: Attribution 3.0 | Timestamp: 2024-02-03 14:33:44.475509

S: Enter Key Press Mechanical Keyboard by alpinemesh | License: Creative Commons 0 | Timestamp: 2024-02-03 14:29:28.512802
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.block.web.builder.ui.activities;

import android.code.editor.common.utils.FileUtils;
import android.os.Bundle;
import android.widget.Toast;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.block.web.builder.R;
import com.block.web.builder.databinding.ActivityLicenseBinding;
import com.block.web.builder.ui.adapters.LicenseListAdapter;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;

public class LicenseActivity extends BaseActivity {
private ActivityLicenseBinding binding;
private ArrayList<License> LicenseList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

binding = ActivityLicenseBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

binding.toolbar.setTitle(R.string.app_name);
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
binding.toolbar.setNavigationOnClickListener(
view -> {
onBackPressed();
});

String LicenseListFileText = FileUtils.readFileFromAssets(getAssets(), "LicenseList.json");
LicenseList = new ArrayList<License>();

try {
JSONArray arr = new JSONArray(LicenseListFileText);
for (int pos = 0; pos < arr.length(); ++pos) {
if (arr.getJSONObject(pos).has("Name") && arr.getJSONObject(pos).has("Path")) {
License License = new License();
License.setLicenseName(arr.getJSONObject(pos).getString("Name"));
License.setLicensePath(arr.getJSONObject(pos).getString("Path"));
LicenseList.add(License);
}
}
} catch (JSONException e) {
}
binding.list.setAdapter(new LicenseListAdapter(LicenseList, this));
binding.list.setLayoutManager(new LinearLayoutManager(this));
}

@Override
protected void onDestroy() {
super.onDestroy();
binding = null;
}

public class License {
private String LicenseName;
private String LicensePath;

public String getLicenseName() {
return this.LicenseName;
}

public void setLicenseName(String LicenseName) {
this.LicenseName = LicenseName;
}

public String getLicensePath() {
return this.LicensePath;
}

public void setLicensePath(String LicensePath) {
this.LicensePath = LicensePath;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.block.web.builder.ui.activities;

import android.code.editor.common.utils.FileUtils;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import com.block.web.builder.R;
import com.block.web.builder.databinding.ActivityLicenseReaderBinding;

public class LicenseReaderActivity extends BaseActivity {
private ActivityLicenseReaderBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

binding = ActivityLicenseReaderBinding.inflate(getLayoutInflater());
// set content view to binding's root.
setContentView(binding.getRoot());

binding.toolbar.setTitle(R.string.app_name);
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());

binding.LicenseText.setAutoLinkMask(Linkify.WEB_URLS);
binding.LicenseText.setMovementMethod(LinkMovementMethod.getInstance());
binding.LicenseText.setText(
FileUtils.readFileFromAssets(getAssets(), getIntent().getStringExtra("Path")));
}

@Override
protected void onDestroy() {
super.onDestroy();
binding = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public void onClick(View arg0) {
Intent setting = new Intent();
setting.setClass(this, SettingActivity.class);
startActivity(setting);
} else if (menuItem.getItemId() == R.id.source_License) {
Intent LicenseActivity = new Intent();
LicenseActivity.setClass(this, LicenseActivity.class);
startActivity(LicenseActivity);
}
return true;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.block.web.builder.ui.adapters;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.block.web.builder.databinding.LayoutLicenseListItemBinding;
import com.block.web.builder.ui.activities.LicenseActivity;
import com.block.web.builder.ui.activities.LicenseReaderActivity;
import java.util.ArrayList;

public class LicenseListAdapter extends RecyclerView.Adapter<LicenseListAdapter.ViewHolder> {

private ArrayList<LicenseActivity.License> LicenseList;
private Activity activity;

public LicenseListAdapter(ArrayList<LicenseActivity.License> LicenseList, Activity activity) {
this.LicenseList = LicenseList;
this.activity = activity;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutLicenseListItemBinding item =
LayoutLicenseListItemBinding.inflate(activity.getLayoutInflater());
View _v = item.getRoot();
RecyclerView.LayoutParams _lp =
new RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
_v.setLayoutParams(_lp);
return new ViewHolder(_v);
}

@Override
public void onBindViewHolder(ViewHolder _holder, final int _position) {
LayoutLicenseListItemBinding binding = LayoutLicenseListItemBinding.bind(_holder.itemView);
binding.name.setText(LicenseList.get(_position).getLicenseName());
binding.name.setOnClickListener(
v -> {
Intent LicenseReader = new Intent();
LicenseReader.setClass(activity, LicenseReaderActivity.class);
LicenseReader.putExtra("Path", LicenseList.get(_position).getLicensePath());
activity.startActivity(LicenseReader);
});
}

@Override
public int getItemCount() {
return LicenseList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View v) {
super(v);
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/file_document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M13,9H18.5L13,3.5V9M6,2H14L20,8V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V4C4,2.89 4.89,2 6,2M15,18V16H6V18H15M18,14V12H6V14H18Z" />
</vector>
34 changes: 34 additions & 0 deletions app/src/main/res/layout/activity_license.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">

<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/appbar">

<com.google.android.material.appbar.MaterialToolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:id="@+id/toolbar" />

</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:id="@+id/nested_scroll_view">

<androidx.recyclerview.widget.RecyclerView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/list" />

</androidx.core.widget.NestedScrollView>

</LinearLayout>
42 changes: 42 additions & 0 deletions app/src/main/res/layout/activity_license_reader.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">

<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
android:id="@+id/appbar">

<com.google.android.material.appbar.MaterialToolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:id="@+id/toolbar" />

</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:id="@+id/nested_scroll_view">

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">

<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/LicenseText" />

</LinearLayout>

</androidx.core.widget.NestedScrollView>

</LinearLayout>
27 changes: 27 additions & 0 deletions app/src/main/res/layout/layout_license_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="16dp">

<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="18sp"
android:id="@+id/name"
android:text="License" />

</LinearLayout>

<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="?attr/colorOnSurface" />

</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/activity_main_drawer_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
android:icon="@drawable/block"
android:title="Blocks Manager"
app:showAsAction="ifRoom" />
<item
android:id="@+id/source_License"
android:icon="@drawable/file_document"
android:title="License and Attribution"
app:showAsAction="ifRoom" />
<item
android:id="@+id/settings"
android:icon="@drawable/setting"
Expand Down
Loading

0 comments on commit 73967f7

Please sign in to comment.