Commit 7c7534ac authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added row layout for the servers

parent 606d9618
......@@ -2,13 +2,14 @@ package com.frostnerd.dnsserver.activities;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import com.frostnerd.dnsserver.R;
import com.frostnerd.dnsserver.database.DatabaseHelper;
import java.util.ArrayList;
import com.frostnerd.dnsserver.adapters.ServersAdapter;
import com.frostnerd.dnsserver.database.entities.main.DNSServerSetting;
import com.frostnerd.dnsserver.util.Util;
import java.util.List;
/**
......@@ -21,14 +22,22 @@ import java.util.List;
* development@frostnerd.com
*/
public class MainActivity extends AppCompatActivity {
private ListView list;
private ArrayAdapter adapter;
private RecyclerView list;
private List<DNSServerSetting> dnsServerSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = findViewById(R.id.list);
new DatabaseHelper(this);
list.setLayoutManager(new LinearLayoutManager(this));
list.setAdapter(new ServersAdapter(this, dnsServerSettings=Util.getMainDatabase(this).getAll(DNSServerSetting.class)));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
menu.findItem(R.id.item_new_server).setIcon(R.drawable.ic_plus);
return true;
}
}
package com.frostnerd.dnsserver.adapters;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import com.frostnerd.dnsserver.R;
import com.frostnerd.dnsserver.database.entities.main.DNSServerSetting;
import java.util.List;
/**
* Copyright Daniel Wolf 2018
* All rights reserved.
* Code may NOT be used without proper permission, neither in binary nor in source form.
* All redistributions of this software in source code must retain this copyright header
* All redistributions of this software in binary form must visibly inform users about usage of this software
* <p>
* development@frostnerd.com
*/
public class ServersAdapter extends RecyclerView.Adapter<ServersAdapter.ViewHolder> {
private LayoutInflater layoutInflater;
private List<DNSServerSetting> dnsServerSettings;
private static final int serverNotRunningColor = Color.parseColor("#F44336");
private String portText;
public ServersAdapter(Context context, List<DNSServerSetting> serverSettings){
layoutInflater = LayoutInflater.from(context);
portText = context.getString(R.string.server_port_label);
this.dnsServerSettings = serverSettings;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(layoutInflater.inflate(R.layout.row_server, parent, false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
DNSServerSetting setting = dnsServerSettings.get(position);
((TextView)holder.itemView.findViewById(R.id.server_name)).setText(setting.getName());
((TextView)holder.itemView.findViewById(R.id.server_port)).setText(portText.replace("[x]", "" + setting.getPort()));
if(!setting.isServerRunning()){
holder.itemView.findViewById(R.id.server_status_indicator).setBackgroundColor(serverNotRunningColor);
((ImageButton)holder.itemView.findViewById(R.id.server_start_stop)).setImageResource(R.drawable.ic_play);
}
}
@Override
public int getItemCount() {
return dnsServerSettings.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
ViewHolder(View itemView) {
super(itemView);
}
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="21dp"
android:height="24dp"
android:viewportHeight="512.0"
android:viewportWidth="448.0">
<path
android:fillColor="#FF000000"
android:pathData="M400,32L48,32C21.5,32 0,53.5 0,80v352c0,26.5 21.5,48 48,48h352c26.5,0 48,-21.5 48,-48L448,80c0,-26.5 -21.5,-48 -48,-48zM394,432L54,432c-3.3,0 -6,-2.7 -6,-6L48,86c0,-3.3 2.7,-6 6,-6h340c3.3,0 6,2.7 6,6v340c0,3.3 -2.7,6 -6,6z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.frostnerd.dnsserver.activities.MainActivity">
<ListView
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:paddingTop="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/button_wrap"
android:layout_toStartOf="@+id/button_wrap"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<View
android:id="@+id/server_status_indicator"
android:layout_width="4dp"
android:layout_height="match_parent"
android:background="#00FF00" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/server_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Server name"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<TextView
android:id="@+id/server_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Port" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/button_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="horizontal">
<ImageButton
android:id="@+id/server_statistics"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="10dp"
app:srcCompat="@drawable/ic_chart_bar" />
<ImageButton
android:id="@+id/server_local_rules"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="10dp"
app:srcCompat="@drawable/ic_database" />
<ImageButton
android:id="@+id/server_edit"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="16dp"
app:srcCompat="@drawable/ic_pencil" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:background="#424242" />
<ImageButton
android:id="@+id/server_start_stop"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="28dp"
android:layout_height="28dp"
app:srcCompat="@drawable/ic_stop" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item_new_server"
android:title="@string/new_server"
app:showAsAction="always" />
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DNS Server</string>
<string name="new_server">Neuer Server</string>
<string name="server_port_label">Port: [x]</string>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">DNS Server</string>
<string name="new_server">New server</string>
<string name="server_port_label">Port: [x]</string>
</resources>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment